“多次出现” boost program_options 的例外
我正在 boost 的program_options(版本1.42)上编写以下代码。这看起来很简单,并且与教程中的内容几乎相同。但是,我收到“multiple_occurrences”错误。进一步调查发现(可能)是“文件名”参数引发了它。
我给出的参数是:
3 1 test.txt 100
我对此没有任何见解......任何帮助将不胜感激。
po::options_description common("Common options");
common.add_options()
("help", "produce help message")
("motif_size", po::value<int>(&motif_size), "Size of motif (subgraph)")
("prob", po::value<double>(&prob), "Probably to continue examining an edge")
("filename", po::value<string>(&input_filename), "Filename of the input graph")
("repeats", po::value<int>(&n_estimates), "Number of estimates")
;
po::options_description all;
all.add(common);
po::positional_options_description p;
p.add("motif_size", 0).add("prob", 1).add("filename", 2).add("repeats", 3);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).
options(all).positional(p).run(), vm);
po::notify(vm);
I am writing the following code on boost's program_options (version 1.42). This seems straight-forward and taken pretty much as is from the tutorial. However, I get a "multiple_occurrences" error. Further investigation discovers that it's (probably) the "filename" parameter that raises it.
The parameters I am giving are:
3 1 test.txt 100
I have no insight to it whatsoever.. any help will be appreciated.
po::options_description common("Common options");
common.add_options()
("help", "produce help message")
("motif_size", po::value<int>(&motif_size), "Size of motif (subgraph)")
("prob", po::value<double>(&prob), "Probably to continue examining an edge")
("filename", po::value<string>(&input_filename), "Filename of the input graph")
("repeats", po::value<int>(&n_estimates), "Number of estimates")
;
po::options_description all;
all.add(common);
po::positional_options_description p;
p.add("motif_size", 0).add("prob", 1).add("filename", 2).add("repeats", 3);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).
options(all).positional(p).run(), vm);
po::notify(vm);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
po::positional_options_description::add
的第二个参数是最大计数,而不是位置。该位置是按照您指定位置选项的顺序隐含的。所以应该是
这是一个可编译的片段
和示例调用。
我原来的答案如下。
什么版本的program_options?我在使用 boost 1.39 时遇到了同样的问题,为了解决这个问题,我最终使用了 boost 1.42。
以下是描述问题的 ticket 的链接,以及适用于您的补丁不想或无法升级您的提升副本。要使用新功能,请执行以下操作
EDIT:
the second parameter to
po::positional_options_description::add
is the max count, not the position. The position is implied in the order you specify the positional options. Soshould be
Here's a compilable snippet
and sample invocation.
My original answer is below.
What version of program_options? I had the same problem using boost 1.39, to solve it I ended up using boost 1.42.
Here's a link to the ticket describing the problem, and a patch to apply if you don't want to or can't upgrade your copy of boost. To use the new functionality, do something like this