In C/C ++, the main () function is used to transmit command line parameters.
To implement the command line parameters, we will define argc and argv in the form of main (INT argc, char * argv []), which can be replaced by your favorite name, not necessarily argv, argc is just a habit. char * argv [] is a pointer array. argv is a pointer array name. argv is not a constant pointer, it is a variable pointer with the characteristics of variables. It can be moved, and thus we can rewrite it to Char ** argv, the Int argc definition returns the number of parameters, so it is marked as an integer (INT ).
# Include <iostream. h>
Void main (INT argc, char ** argv)
{
Cout <"Command Line Parameter Parsing" <Endl;
Cout <"number of parameters:" <argc <Endl;
Cout <"output parameter value:" <Endl;
Int COUNT = 0;
While (count <argc) // while (argv! = NULL)
{
Cout <"no." <count + 1 <"parameter value:" <argv [count] <Endl;
Count ++;
}
Return;
}
To debug C/C ++ProgramEnter a B c d e in a variable line with a total of five parameters, separated by spaces.
Then run the program and the result is as follows:
The following six parameters are displayed: by default, the Directory of the executable file is set to the first value of the array argv. Therefore, there are a total of six parameter values.