问题标签 [boost-program-options]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1168 浏览

c++ - Boost.program_options:implicit_value 和 Unicode 导致编译时错误

我正在使用 Boost.program_options 库,需要指定具有 Unicode 支持的implicit_value。

对于 ansi-string 此代码工作正常

但是如果我像这样使用 Unicode 支持

我收到以下错误:

我做错了什么?

0 投票
1 回答
195 浏览

c++ - 如何在不使用变量的情况下在 Boost Program Options 中启用其他选项?

我使用程序选项来解析我的应用程序的命令行选项。

我有几个选项,如 -Ox、-Oy、-Oz,... 我想要一个超级选项 -Oall 启用 Ox 和 Oy 以及另一个启用 Oz 和 Ow 的 -Osub。

有没有办法使用 Boost Program Options 做到这一点?

一开始想查看Oall的值,然后手动启用Ox和Oy,但是解析后无法编辑值。

我想避免使用变量来存储 Ox、Oy 的值,因为我可以有很多这些选项。

谢谢

0 投票
1 回答
992 浏览

c++ - boost program_options:帮助与有意义的选项

有没有一种简单的方法可以将帮助选项与“真实”程序选项分开?事实上,是否可以定义选项层次结构,例如BNF

还是有更好的方法来实现这一目标?我应该恢复精神吗?

0 投票
2 回答
28453 浏览

c++ - Vector arguments in Boost Program Options

I have two related questions:

  1. What is the simplest way to allow passing a series of values, using Boost Program Options? My aim is to avoid prog --opt 1 --opt 2 --opt 3 and have prog --opt 1 2 3 instead.

  2. What is the simplest way to have an option that takes exactly two numbers, e.g. prog --opt 137 42?

(I don't need any "free" program parameters.)

0 投票
2 回答
2747 浏览

c++ - boost::program_options 如何重新加载一个值

我想从配置文件中重新加载一些值。我知道po::store如果它们存在于variables_map. 即使值已经存在,是否有替代方法可以替换它们?

我尝试删除即将从 中重新加载的值variables_map,但po::store无论如何都没有添加新值(即使旧值也无法访问)。

0 投票
3 回答
11915 浏览

c++ - Boost 程序选项允许输入值集

有没有办法为参数设置一组允许的输入变量?例如参数“arg”只能有字符串值,如“cat”和“dog”。

0 投票
2 回答
3490 浏览

c++ - Boost program options with default values always present when using vm.count()

I've been trying to validate my passed options with boost::program_options. My command has several modes, each of which have associated params that can be specified. What I'm trying to do is ensure these associated params are passed with the mode, i.e.

Where --fly is the mode and --magic-wings-threshold is an associated param. What I've noticed is if --magic-wings-threshold has a default value, e.g.

then I can't use

to detect if the user passed that param.

It appears that default value params are always passed and detected in vm.count(). Does anyone know a workaround or alternative?

0 投票
1 回答
586 浏览

c++ - 为 boost::program_options 设置精度

有没有办法改变 boost::program_options 如何格式化 a 的帮助文本中选项的默认值program_options::options_description(可以通过 获得cout << description)?特别是我的默认值是浮点数,所以通常的十进制到二进制转换给了我一个看起来--arg (0.100000001)很丑陋的帮助文本。

使用cout << setprecision(4)不起作用,因为 program_options 将<<自己设置为某些内部流的默认值以首先进行格式化(至少这是我通过查看源代码推断出来的),而得到<<cout是结果字符串(流?)。

谢谢。

0 投票
1 回答
1049 浏览

c++ - 如何重载 operator<< 以与 boost::program_options 默认值输出一起使用?

我正在使用 boost::program_options 并希望将类似“域”的选项传递给我的程序。这样的域很简单:

我为这个选项类编写了一个自定义验证器,效果很好。现在我想添加一个默认值,如

boost::program_options 调用操作符<<:

我添加了这个,但仍然收到相同的错误消息:

如何定义 operator<< 以在自定义选项描述中与默认值输出一起使用?


我又做了一些调查。错误发生在boost/lexical_cast.hpp:1147 In member function bool boost::detail::lexical_stream_limited_src<CharT, Traits, RequiresStringbuffer>::shl_input_streamable(InputStreamable&) [with InputStreamable = const CDomain<long double>, CharT = char, Traits = std::char_traits<char>, bool RequiresStringbuffer = true]

这可能是一个命名空间问题,但ostream& operator<<(ostream& o, CDomain<T>& d)进入 boost::detail 并没有解决问题。

0 投票
0 回答
348 浏览

c++ - 获取指向 argv 元素的指针 Boost Program Options

我假设传递给主函数的字符串数组argvvoid main( int argc, char* argv[] )应用程序期间保持在范围内。

因此,我的问题是是否有可能使用 boost::program_options 来获取指向 argv 中代表特定选项的实际元素的指针。

也就是说,不是std::string在解析时分配 a ,而是可以只获取一个指向字符串选项值开头的指针。