我试图允许使用boost的“多空”选项(版本1.46)。我的印象是,使*伪装*助推风格将允许这样的事情。鉴于此代码:C++ boost程序选项允许长期选项
// Declare the supported options.
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("RunTimeE,rtttt", boost::program_options::value<std::string>(), "RunTimeE Version")
;
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
.options(desc)
.style(boost::program_options::command_line_style::unix_style
| boost::program_options::command_line_style::allow_long_disguise)
.run(),
vm);
boost::program_options::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
if (vm.count("RunTimeE")) {
cout << vm["RunTimeE"].as<std::string>() << endl;
return 1;
}
会产生:
./output --help
Allowed options:
-h [ --help ] produce help message
-r [ --RunTimeE ] arg RunTimeE Version
但我希望它产生:
./output --help
Allowed options:
-h [ --help ] produce help message
-rtttt [ --RunTimeE ] arg RunTimeE Version
任何人都可以在这方面帮助?
谢谢。
如果不编写自己的[自定义分析器](http://www.boost.org/doc/libs/1_56_0/doc/html/program_options/howto.html),我不确定这是可能的。您正在指定一个长选项'RunTimeE'和一个简短选项'rtttt',但短期选项根据定义只有一个字符。你可以通过指定'allow_long_disguise'来使用长选项,但我没有看到允许你有两个长选项。事实上,长期和短期有两个长期选择的点是什么? – sjdowling 2014-10-18 13:31:18