Loading

c_cpp-带参数的main函数

代码

最终运行的时候会发现命令名也是一个参数,也就是argv[0]

int main(int argc, char* argv[]){
	/**
	*这两个参数的形式是固定的
	*第一个参数代表传入参数的个数 argument count的缩写
	*第二个参数是表示参数向量 argument vector
	*/
	int i = 0;
	while (argc>0)
	{
		printf("%s\n", argv[i]);
		argc--;
		i++;
	}
	return 0;
}
运行
在cmd中运行该程序并传入参数

cmd中

在powershell中运行该程序并传入参数

powershell中

在vs中配置传入参数



posted @ 2021-03-25 19:45  克豪  阅读(110)  评论(0)    收藏  举报