Boost logo

Boost Users :

Subject: Re: [Boost-users] [Options Description] positional_options_description throw exception
From: Vladimir Prus (vladimir_at_[hidden])
Date: 2010-03-24 12:41:33


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net