Folks, 我在这里使用了get_opt_long的示例:https://linux.die.net/man/3/getopt_long_only 我仍然对如何在我的情况下使用感到困惑。在我的情况下,我有多个选项。需要关于如何设置getopt_long以正确传递命令行参数的建议
-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, - 作为命令行参数。我强迫所有选项都使用unic字符。
我而块具有
case 's':
seed = atoi(optarg);
break;
case 'n':
num = atoi(num);
case 'a':
ask->all = true;
break;
感谢
我建议您为您的问题添加其他相关标签。对于C++用户来说,使用'getopt'进行命令行解析是很少见的,因为C++领域还有其他更好的库 – WhiZTiM
@WhiZTiM argp?您对多个选项的评论提示。 –
你可以提供一些选择吗? – Romeo