Boost logo

Boost Users :

Subject: Re: [Boost-users] program options: unrecognized command-line options
From: Christoph Duelli (duelli_at_[hidden])
Date: 2009-01-14 12:54:25


Deane Yang wrote:

> I'm using the program options library to parse both command-line and
> configuration file parameters. I'd like to know how to find command-line
> arguments that are *not* registered and therefore not recognized by the
> parser. I want to be able to print a warning message like "Following
> arguments were ignored:....".

I did it like that:

// assume that options is a std::vector<std::string> containing
// the passed options (argv[])
 po::options_description desc; // contains the options your prog supports

 po::variables_map vm;
 po::command_line_parser parser(options).allow_unregistered().options(desc);

 po::parsed_options parsed = parser.run();
 po::store(parsed, vm);
 po::notify(vm); // recognized options

 std::vector<std::string> unrecognizedOptions =
   po::collect_unrecognized(parsed.options, po::include_positional);

This is documented at
doc/html/program_options/howto.html#id3458178 in your Boost docs.

Best regards
Christoph


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