Questions tagged «boost-program-options»

4
使用Boost库程序选项的必需参数和可选参数
我正在使用Boost程序选项库来解析命令行参数。 我有以下要求: 一旦提供了“帮助”,所有其他选项都是可选的。 一旦不提供“帮助”,则所有其他选项都是必需的。 我该如何处理?这是我处理此问题的代码,我发现它非常多余,我认为必须很容易做到,对吗? #include <boost/program_options.hpp> #include <iostream> #include <sstream> namespace po = boost::program_options; bool process_command_line(int argc, char** argv, std::string& host, std::string& port, std::string& configDir) { int iport; try { po::options_description desc("Program Usage", 1024, 512); desc.add_options() ("help", "produce help message") ("host,h", po::value<std::string>(&host), "set the host server") ("port,p", po::value<int>(&iport), "set …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.