This article describes the command line parameters: argc and argv.
C ++ProgramThe main function can contain two parameters. These two parameters are respectively an integer and an array pointing to a pointer of the struct type. Integer Parameters record the number of command line parameters that you enter in the command line of the program. The char * [] character pointer array points to each parameter in the command line. Although the two parameters can be named with any identifier, it is customary to always use argc and argv.
They have never been defined in our previous programs.
Note: The main function does not define the parameters. It is also the only function that does not need to define the parameters.
The argc parameter must be at least 1. If you enter a parameter in the command line, it is larger than 1. Argv points to at least one struct pointer in the array, that is, argv [0]. It usually points to the executable file name of the program, and some versions also include the path of the program.
ExampleCodeAs follows:
#include <iostream> </P> <p> // /// // <br //> // The main () function. <br/> //////////////////////////////////// //// <br/> int main (INT argc, char * argv []) <br/>{< br/> STD: cout <"this program is" <argv [0] <STD: Endl; <br/> for (INT Arg = 1; arg <argc; arg ++) <br/> STD: cout <"argument" <Arg <": "<br/> <argv [Arg] <STD: Endl; </P> <p> return 0; <br/>}