关闭

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

标签: C++argcargv
127人阅读 评论(0) 收藏 举报
分类:

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 !



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:617次
    • 积分:47
    • 等级:
    • 排名:千里之外
    • 原创:4篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档