#include <iostream>Save this program as argument.cpp and compile it. If we run the program:
using namespace std;
int main(int argc, char * argv[])
{
for (int i = 1; i<argc; i++)
cout << argv[i] << ' ';
cout << endl;
}
$ ./a.out eenie meenie miney moewe see that this program echoes the command-line arguments. We have a main function header of the form int main(int argc, char * argv[]); argc is the number of terms in the command-line, including the command name, and argv[] is an array of strings which contains the command name in argv[0], and then all the command-line arguments in argv[1] through argv[argc-1]. The arguments are delimited by blanks and, so, no spaces will appear in any of the arguments passed into the program.
eenie meenie miney moe
$
Assignment:
Modify argument.cpp so that it
converts the arguments to integers, computes their sum, and then prints
out this value. For example,
$ ./a.out 3 6 10
Sum is: 19
$