main函数的参数问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 12:37:24
main函数可以带有参数,现在想编程看一下具体的输入及输出,就是说:我想通过输入参数如teacher student,然后运行时能在屏幕上看到输入的teacher和student这两个参数。写了一个程序,编译通过,但是,屏幕上出现的是该程序的保存路径。不知道是怎么回事。如果想看到自己输入的参数,该怎么办呢?本人菜鸟,还望高手指点。

#include <iostream>
#include <string>

using namespace std;

void main(int argc,char* argv[])
{
int i=0;
while(i<argc)
{
cout<<*argv++<<endl;//cout<<argv[i]<<endl;
i++;
}
cin.get();
}

#include <iostream>
#include <string>

using namespace std;

void main(int argc,char* argv[])
{
int i=0;
while (i<argc) cout<<argv[i++]<<endl;
cin.get();
}

arg[0] 保存的是 DOS 路径,
从 arg[1] 开始数