References:
C ++ language main function, often with parameters argc, argv, as follows:
int main(int argc, char** argv)
int main(int argc, char* argv[])
Effect of these two parameters: argc is the number of command line arguments (in whitespace separated) stores all the argv command line parameters are hello.exe if your program, if the program is run from the command line, (first should enter at the command line using the cd command to hello.exe file directory) command is run:
hello.exe Shiqi Yu
Then, the value of argc is 3, argv [0] is "hello.exe", argv [1] is "Shiqi", argv [2] is "Yu".
The following program demonstrates the use of argc and argv:
#include <stdio.h> int main(int argc, char ** argv) { int i; for (i=0; i < argc; i++) printf("Argument %d is %s.\n", i, argv[i]); return 0; }
If the above code is compiled hello.exe, then run
hello.exe a b c d e
Will be
Argument 0 is hello.exe. Argument 1 is a. Argument 2 is b. Argument 3 is c. Argument 4 is d. Argument 5 is e.
run
hello.exe lena.jpg
Will be
Argument 0 is hello.exe. Argument 1 is lena.jpg.