Boost Program Options Examples
On Debian systems, you find it in /usr/share/doc/libboost-doc/examples/libs/program_options. Otherwise, I suggest to download the archive from boost.org and have a look there.
On Debian systems, you find it in /usr/share/doc/libboost-doc/examples/libs/program_options. Otherwise, I suggest to download the archive from boost.org and have a look there.
If I understand the problem correctly, you want to parse command line options of the following form: [–generic-option …] cmd [–cmd-specific-option … ] Here is my example solution. For clarity I’m going to omit any validation code, but hopefully you can see how it would be added fairly simply. In this example, we have the … Read more
default_value() is the value that will be put in the variables_map if the user didn’t specify another value: ./a.out # implies width=75 if that’s the default_value for width ./a.out –width=80 # default_value not used implicit_value() is the value that will be used if the user specifies the option but without an adjacent value. ./a.out –width … Read more
This is a late answer but I hope it helps someone. You could easily use the same technique in item #1, except you need to add another validation on the number of items in your vector: from rcollyer’s example: namespace po = boost::program_options; po::option_descriptions desc(“”); desc.add_options() (“opt”, po::value<std::vector<int> >()->multitoken(), “description”); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), … Read more
I’ve run into this issue myself. The key to a solution is that the function po::store populates the variables_map while po::notify raises any errors encountered, so vm can be used prior to any notifications being sent. So, as per Tim, set each option to required, as desired, but run po::notify(vm) after you’ve dealt with the … Read more