C++ main函数传参

阅读 91

2022-10-09


#include <iostream>

using namespace std;

int main(int argc, char ** argv)
{
for (int i=0;i<argc;i++)
{
cout << argv[i] << endl;
}

return 0;
}

argc 获取的是传参的个数, argv 是一个字符串的数组,具体的参数内容就在其中。

编译运行结果

[work@localhost lgit]$ g++ main.cpp 
[work@localhost lgit]$ ./a.out -o -p fu baidu
./a.out
-o
-p
fu
baidu
[work@localhost lgit]$


精彩评论(0)

0 0 举报