Question: C++ #include using namespace std; int main(int argc, char* argv[]) { //print cmd line arguments for (int i = 0; i < argc; i++) {

C++

#include using namespace std;

int main(int argc, char* argv[])

{ //print cmd line arguments

for (int i = 0; i < argc; i++) {

cout << endl << argv[i];

} cout << endl; return 0;

}

Perform the following tasks to the code above

1.Add a preprocessor directive to include the string class.

2. Declare a string pointer named args at the top of the main function.

3. Create a dynamic array of strings that has the same size as argv does.

4. Using a for loop, set each string in args to a corresponding C-string in argv.

You can convert a C-string to a string simply by assigning the C-string to the string.

5. Change the code to print out from the args array instead of the argv array.

6. Add a line just before the return statement to delete the args array.

7. Add lines in the code to print out the value and the address of args in the following spots ::_ after the declaration of args, after creating the dynamic array, after filling the array with strings, after deleting the array

8. set args to NULL after the deletion statement

/////Please help. I am stuck in doing the above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!