A lot of new programmer wonder what are the arguments passed to main. I am going to tell you about them.
The program has two argument in main as in
main(int argc, char *argv).
basically, argc is an integer that contains the number of
arguments passed to the program and argv is an array of the arguments that was
argv is always the program name itself.
using namespace std;
int main( int argc, char* argv )
cout << "The name used to start the program: " << argv[ 0 ]
<< "\nArguments are:\n";
for (int n = 1; n < argc; n++)
cout << setw( 2 ) << n << ": " << argv[ n ] << '\n';
If you compile this from the command line and enter:
D:\prog\test> a Hello world!
The name used to start the program: a