linux ubuntu 编写c/c++ 获取命令行传入参数示例
g++ test.cpp -o test
./test -d video.jpg
test.cpp 代码如下
#include <iostream>
#include <unistd.h>using namespace std;int main(int argc, char* argv[]) {//参数变量初始化string db_path;int ch;opterr = 0; //选项错误时不让报错while ((ch = getopt(argc, argv, "d:")) != -1) {switch (ch) {case 'd': db_path = string(optarg); break;}}cout << db_path << endl;return 0;
}
更多多资讯或疑问内容请关注 微信公众号 “让梦飞起来” 或添加小编微信, 后台回复 “Python” ,领取更多资料哦