您的位置:首页 > 编程语言 > C语言/C++

The meaning of "argc" and "argv" in programming

2015-07-06 17:23 507 查看
We often find two parameters named "argc" and "argv" in main function like,

int main(int argc, char** argv)
{return 0;}

"argc" is the number of parameter we input in command line. "argv" saves all the paramters what we input.

A test demo code shows as follows:

#include <iostream>
using namespace std;
int main(int argc, char ** argv)
{
int cnt;
for (cnt=0; cnt<argc; cnt++)
cout<<"Parameter "<<cnt<<" is " <<argv[i];
return 0;
}

After I built this demo and generated a file named "demo.exe", I run this command in my terminal, and got the output like this:
demo.exe hello world !
Parameter 0 is demo.exe
Parameter 1 is hello
Parameter 2 is world
Parameter 3 is !
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C++ argc argv