需要有关如何设置getopt_long以正确传递命令行参数的建议
need suggestions on how to setup getopt_long to properly pass command line arguments
伙计们, 我在这里回顾了使用get_opt_long的示例:https://linux.die.net/man/3/getopt_long_only 而且我仍然对如何在我的情况下使用感到困惑。我有多种选择。
-Aa => ask for all
-As => ask for stats
-Af => ask for file
-seed => pass seed
-num => repeat times
我可以让 -seed 和 -num 工作,但不确定如何合并 -Ap、-ax-Af
这是我的选项结构:
enter code here
{"seed" , required_argument , NULL , 's'} ,
{"num" , required_argument , NULL , 'n'} ,
{"ask_all" , no_argument , NULL , 'a'} ,
{"ask_stat" , no_argument , NULL , 't'} ,
{NULL , 0 , NULL , 0}
另外,我如何使用-Ap,-As作为命令行参数。我被迫在我的所有选择中使用统一字符。
我的同时块有
case 's':
seed = atoi(optarg);
break;
case 'n':
num = atoi(num);
case 'a':
ask->all = true;
break;
谢谢
两种可能的解决方案:
- 对
"Aa"
、"As"
和"Af"
使用长参数 - 使用一个短参数
'A'
该参数采用必需的参数,即'a'
、's'
或'f'
字符
相关文章:
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 如何处理linux终端中带有负号(-)的C++中的命令行参数
- 使用 C++ 将命令行参数拆分为参数/向量
- 如何在OMNET++中添加专门的命令行参数?
- 如何在不传递命令行参数的情况下在 c++ 中设置环境变量
- atoi() 在应用于大型命令行参数时会产生不正确的值
- 命令行参数,cant 或两个变量
- 在 Windows 中使用 boost::p rogram_options 从命令行参数读取 Unicode 字符
- 如何在 Android/NDK 上将命令行参数从 gradlew.bat 传递到 Clang
- 编写一个将 LLVM IR 文件作为命令行参数的程序
- 通过命令行参数获取llvm ir文件时面临问题
- 有没有办法根据命令行参数定义数组大小?运行时与编译时实例化?
- 如何在不使用文件扩展名的情况下使用命令行参数打开C++中的文本文件?
- 命令行参数在不到 3 个 LOC 中 int?
- 在命令行参数中使用引号
- 在VS2013中使用devenv (C++)传递命令行参数argv
- 二进制数据作为命令行参数
- 如何在 C++11 中创建具有命令行参数大小的动态数组?
- 需要有关如何设置getopt_long以正确传递命令行参数的建议
- Bash 脚本和命令行参数