argc代表参数计数,而argv代表参数值。这些是开始执行时传递给主函数的变量。当我们运行一个程序时,我们可以为该程序提供参数,例如:
$ ./a.out hello
问候是可执行文件的参数。可以在程序中访问它。
#include<iostream>
using namespace std;
int main(int argc, char** argv) {
   cout << "This program has " << argc << " arguments:" << endl;
   for (int i = 0; i < argc; ++i) {
      cout << argv[i] << endl;
   }
   return 0;
}当您像这样编译并运行该程序时:
$ ./a.out hello people
这将给出输出:
该程序有3个参数
输出结果
C:\Users\user\Desktop\hello.exe hello people