Use basic form of the command-line arguments
-
argc
: Is the number of parameters初始值为1
.
argv[]
: The deposit is the first address of a command line parameter, the initial value from the1
start.as follows:
The position of program execution argv[0] NULL argv[1] -
Code
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { //程序执行部分 return 0; }
Examples
-
Use
cmd
the calling program, given the parameters, execute the program.
cmd 可执行程序路径 参数1 参数2
-
Characters read out, and output.
-
读取文件
And输出到文件
when used‘<'
, and‘>’
(note, not have the main functionargv
andargc
input parameters) -
Code:
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { for (int i = 1; i <= argc; i++) { cout << argv[i] << endl; } return 0; }
-
test: