Parameter list
Linux Command line specification
- Short parameter: Starts with a single cross, followed by a single character, for example: ls-h
- Long parameter: begins with a double-cross, followed by a string, for example: LS--help
Program Access parameter list method:
- Parameters argc and argv of the main function
- The program accepts the input parameters of the command line and interprets the
Writing programs, outputting command-line arguments
#include <iostream>using namespacestd;intMainintargcChar*argv[]) {cout<<"The program name is:"<< argv[0] <<" ."<<Endl; if(Argc >1) {cout<<" with"<< ARGC-1<<"args as follows:"<<Endl; for(inti =0; i < argc; i++) {cout<< Argv[i] <<Endl; } } Else{cout<<" with"<< ARGC-1<<"arguments."<<Endl; } return 0;}
Parameter list:
Definition of an option array
struct type option: The system is defined and can be used directly
Header file: getopt.h
struct option
{
Option long name
const char *name;
Option has additional parameters: 0, none, 1, available; 2, optional;
int has_arg;
Point to Integer, which holds the value of Val, set to 0
int *flag;
Option short name
int Val;
};
function Getopt_long ()
-V/--verbose: output complex information
C + + Learning Note 16:linux System programming Fundamentals 1