boost program_option不区分大小写的解析 [英] boost program_option case insensitive parsing
问题描述
有没有人弄清楚如何获得boost程序选项来解析不区分大小写的参数列表
Has anyone worked out how to get boost program options to parse case insensitive argument lists
在boost文档中,它似乎受支持.参见 http://www.boost.org/doc/libs/1_53_0/boost/program_options/cmdline.hpp
In the boost documentation, it appears that it is supported. See http://www.boost.org/doc/libs/1_53_0/boost/program_options/cmdline.hpp
即,设置style_t枚举标志,例如long_case_insensitive.但是,我不确定该怎么做.例如,如何获取以下代码段以接受--Help或--help或--HELP
Namely, setting the style_t enum flag such as long_case_insensitive. However, I'm not sure how to do it. Eg how would you get the following code snippet to accept --Help or --help or --HELP
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<double>(), "set compression level")
;
po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 0;
}
推荐答案
调用store时可以修改样式.我相信这应该对您有用:
You can modify the style when you call store. I believe this should work for you:
namespace po_style = boost::program_options::command_line_style;
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc)
.style(po_style::unix_style|po_style::case_insensitive).run(), vm);
po::notify(vm);
这篇关于boost program_option不区分大小写的解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!