int main(int argc, char* argv[])
一:解释
argc : 是命令行总的参数个数;
argv[ ]: 是argc个参数,其中第0个参数是程序的全名(包含路径),之后的参数命令行后面跟的用户输入的参数。
example:
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout<<"the name of program: \n"<<argv[0]<<endl;
cout<<"=================================="<<endl;
cout<<"the item of argv[]:"<<endl;
for(int i=0;i<argc;i++)
{
cout<<argv[i]<<endl;
}
system("pause");
return 0;
}
二.运行
方法一:
在DOS终端输入:
D:\科研\test1210\Debug\test1210.exe hello world!
执行结果为:
方法二:
项目》属性》调试》命令行参数 输入 “hello world!”
执行结果如上。
Reference:
1:http://blog.youkuaiyun.com/lambol_8309/article/details/4524964
2:http://xylvhp.blog.163.com/blog/static/31123614200811253113449/