【发布时间】:2012-04-16 17:09:15
【问题描述】:
我使用boost::program_options 为我的应用程序提供命令行解析接口。我想配置它来解析选项,
using namespace boost::program_options;
options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("version,v", "print the version number")
("include-path,I", value< vector<string> >(), "include path")
("input-file,i", value<string>(), "input file");
positional_options_description p;
p.add("input-file", 1);
variables_map vm;
parsed_options parsed = command_line_parser(ac, av).
options(desc).positional(p).run();
store(parsed, vm);
notify(vm);
我想对其进行配置,以便在最后一次切换之后的每个标记都以向量的形式返回。我已经尝试按照 Boost 文档中给出的示例使用 collect_unrecognized,但我遇到了一些问题,因为我也在为输入文件使用位置参数。
基本上我想这样做。如果我有:
./program -i "inputfile.abc" argument1 argument2 argument3
我希望它将inputfile.abc 存储在input-file 值中,并返回argument1、argument2 和argument3 中的vector<string> 作为未经请求的参数。
然而,我也希望能够有一个位置参数,以便
./program "inputfile.abc" argument1 argument2 argument3
会给我同样的结果。
很抱歉,如果您已经提出此问题并感谢您的帮助。
【问题讨论】:
标签: c++ boost boost-program-options