参考来源:https://blog.csdn.net/u014106566/article/details/84141718
#include<iostream> using namespace std; int main(int argc, char ** argv){ cout<<" argc = "<<argc<<endl; int n=0; for(int i=0;i<argc;i++){ cout<<"argv[i] = "<<argv[i]<<endl; } return 0; }
编译:
g++ main.cpp
执行:
./a.out tt 123 456
结果:
argc = 4 argv[0] = ./a.out argv[1] = tt argv[2] = 123 argv[3] = 456
所以,argc 就是命令行输入参数个数 (argument counter),argv 就是命令行输入参数(argument vector)。