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

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
个人分类: C++
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭