c++ - No arguments default behavior with Boost.Program_options? -


i using boost::program_options parse command line , adapted code tutorial following:

try {     po::options_description desc("allowed options");      desc.add_options()         ("help,h", "output message")         ("width,w", po::value<int>()->required(), " width")     ;      po::positional_options_description p;     p.add("width", 1);      po::variables_map vm;     po::store(po::command_line_parser(argc, argv).               options(desc).positional(p).run(), vm);      if (vm.count("help")) {         std::cout << "usage: " << av[0] << &p <<  std::endl;         return 0;     }      po::notify(vm);      if (vm.count("width")) {         std::cout << "width: " << vm["width"].as<int>() << "\n";     } } catch (std::exception& e) {     std::cout << e.what() << std::endl;     return 1; } catch (...) {     std::cout << "exception of unknown type!" << std::endl; } 

i'd show when no arguments passed didn't found way total number of arguments variables_map without relying on argc.

argc way go here, program_options not expose how many options set. don't overengineer.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -