Reprinted from
Http://www.opencv.org.cn/index.php/Main%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0argc%EF%BC%8Cargv%E8%AF%B4%E6%98%8E
The main function in C/C ++ often carries the argc and argv parameters, as follows:
Int main (INT argc, char ** argv)
Int main (INT argc, char * argv [])
What are the functions of these two parameters? Argc refers to the number of input parameters in the command line. argv stores all command line parameters. Assume that your program is hello.exe. If you run this program on the command line
Command to enter the directory where the hello.exe file is located) run the following command:
Hello.exe Shiqi Yu
The value of argc is 3, argv [0] is "hello.exe", argv [1] is "Shiqi", and 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 false statement code is compiled into hello.exe, run
Hello.exe a B c d e
Will get
Argument 0 is hello.exe.
Argument 1 is.
Argument 2 is B.
Argument 3 is C.
Argument 4 is D.
Argument 5 is E.
Run
Hello.exe lena.jpg
Will get
Argument 0 is hello.exe.
Argument 1 is lena.jpg.