Command Line Arguments in C++

The main fuction in a C++ program can either be defined as:


The second variation allows you to specify command line arguments to be passed to your main function. You may have as many command line arguments as you like. The number of arguments is stored in argc and argv is a array of points to strings which represent the parameters that you passed in to main. Argc is always at least equal to 1 because argv[0] is the name of your program. So if your program is called sort and you typed "sort file1 file2", the following parameters to main are set: argc = 3, argv[0] = sort, argv[1] = file1, and argv[2] = file2.

To demonstrate, write the following code:
Compile this a run "a.out param1 param2 param3" and the arguments will be printed.