在VC++中如何向带参数的main()函数传参呢?
#include<iostream>usingnamespacestd;intmain(intargc,char*argv[])//argc=4;argv[0]=test...
# include <iostream>
using namespace std;
int main(int argc, char * argv[]) //argc = 4; argv[0] = test, argv[1] = apple, argv[2] = pear, argv[3] = orange.
{
cout << "命令行的文件后有" << argc - 1 << "个参数, 分别是:";
while (argc > 1)
{
++argv;
cout << *argv << endl;
--argc;
}
return 0;
}
//如果命令行如下:
//test apple pear orage 展开
using namespace std;
int main(int argc, char * argv[]) //argc = 4; argv[0] = test, argv[1] = apple, argv[2] = pear, argv[3] = orange.
{
cout << "命令行的文件后有" << argc - 1 << "个参数, 分别是:";
while (argc > 1)
{
++argv;
cout << *argv << endl;
--argc;
}
return 0;
}
//如果命令行如下:
//test apple pear orage 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询