当使用boost :: program_options,一个人如何设置参数的名称? [英] When using boost::program_options, how does one set the name of the argument?
问题描述
在使用的boost :: program_options
,我怎么了的boost :: program_options设置参数的名称::值<>( )
?
的#include<&iostream的GT;
#包括LT&;升压/ program_options.hpp>诠释的main()
{
提高:: program_options :: options_description递减; desc.add_options()
(宽度,助推:: program_options ::值<&诠释GT;()
给宽度); 性病::法院LT&;<说明<<的std :: ENDL; 返回0;
}
以上code给出:
--width ARG给宽度
我要的是更多的东西描述要替换 ARG
名称 NUM
:
--width NUM给宽度
在提升(1.53)的最新版本,你不再需要使自己的类蒂姆·西尔维斯特建议。这是可能的使用方法:升压:: program_options :: typed_value。在哪个值名称可以配置的。
的#include<&iostream的GT;
#包括LT&;升压/ program_options.hpp>
使用boost :: program_options :: typed_value;
使用boost :: program_options :: options_description;INT主(INT ARGC,字符** argv的){
options_description DESC(使用); INT someValue中;
汽车someOption =新typed_value< decltype(someValue中)>(安培; someValue中);
someOption->值名称(民);
desc.add_options()
(一些选项,S,someOption的选项\\ n); 性病::法院LT&;<说明<<的std :: ENDL;
返回0;
}
将显示一个配置参数名:
用法:
-s [ - 有些选项] NUM选项
When using boost::program_options
, how do I set the name of an argument for boost::program_options::value<>()
?
#include <iostream>
#include <boost/program_options.hpp>
int main()
{
boost::program_options::options_description desc;
desc.add_options()
("width", boost::program_options::value<int>(),
"Give width");
std::cout << desc << std::endl;
return 0;
}
The above code gives:
--width arg Give width
What I want is to replace the arg
name with something more descriptive like NUM
:
--width NUM Give width
In the current version of boost (1.53) you don't need anymore to make your own class as Tim Sylvester proposed. It's possible to use : boost::program_options::typed_value. On which value_name can be configured.
#include <iostream>
#include <boost/program_options.hpp>
using boost::program_options::typed_value;
using boost::program_options::options_description;
int main(int argc, char **argv) {
options_description desc("Usage");
int someValue;
auto someOption = new typed_value<decltype(someValue)>(&someValue);
someOption->value_name("NUM");
desc.add_options()
("some-option,s", someOption, "The option\n");
std::cout << desc << std::endl;
return 0;
}
Will display a configured argument name :
Usage:
-s [ --some-option ] NUM The option
这篇关于当使用boost :: program_options,一个人如何设置参数的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!