
Sakharuk, Vladimir wrote:
Trying to access positional arguments with sample program bellow:
If I run: "a.out one" Error: unknown option positional Same error I got on "a.out -h one" and "a.out one -h"
If I run: "a.out one two" Error: too many positional options
But "a.out -h works" Thanks \/.
namespace po=boost::program_options; po::options_description cmds("Options"); cmds.add_options() ("help,h", "output help message");
po::positional_options_description positional; positional.add("positional", 1);
po::variables_map vm; po::parsed_options parsed = po::command_line_parser(argc, argv).options(cmds).positional(positional).run();
Per documentation, this code only makes the first positional option be treated as option named 'positional'. You still need to define such an option inside an options_description object, since otherwise the library will have no idea what type it has and what to do with it. Does this help? - Volodya