argc和argv学习

转自:https://stackoverflow.com/questions/3024197/what-does-int-argc-char-argv-mean

1.介绍

argc:c是指count,传参个数,至少为1,表示执行的文件名;

argv:v指vector,即传参向量。

#include <iostream>

int main(int argc, char** argv) {
    std::cout << "Have " << argc << " arguments:" << std::endl;
    for (int i = 0; i < argc; ++i) {
        std::cout << argv[i] << std::endl;
    }
}

//输出:
Have 4 arguments:
./test
a1
b2
c3

 

posted @ 2023-04-24 09:13  lypbendlf  阅读(137)  评论(0编辑  收藏  举报