Wil*_*mKF 7 c++ boost boost-program-options
我正在使用boost :: program_options来指定我的C++应用程序的参数.有没有办法指定一组备选方案中需要一个参数?
<application> [--one int-value1 | --two string-value2 | --three]
Run Code Online (Sandbox Code Playgroud)
另外,在上述中,用户必须通过替代的正好一个:--one,--two,或--three.
我可以手动执行此操作,但希望有一个内置机制而不是这个:
#include <boost/program_options.hpp>
namespace po = boost::program_options;
int main(int argc, char *argv[]) {
po::options_description options;
int band;
std::string titles_path;
options.add_options()
("one", po::value<int>(&band)->default_value(1))
("two", po::value<std::string>(&titles_path))
("three");
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, options), vm);
if (1 != (vm.count("one") + vm.count("two") + vm.count("three"))) {
std::cerr << options << std::endl;
return -11;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
使用提升选项有更好的方法吗?