Questions tagged [boost-program-options]

Boost.Program_options is a C++ library that allows program developers to obtain (name, value) pairs from the user via conventional methods such as command line and config file.

Boost.Program_options is a C++ library that allows program developers to obtain program options, that is (name, value) pairs from the user, via conventional methods such as command line and config file.

Why would you use such a library, and why is it better than parsing your command line by straightforward hand-written code?

  • It's easier. The syntax for declaring options is simple, and the library itself is small. Things like conversion of option values to desired type and storing into program variables are handled automatically.
  • Error reporting is better. All the problems with the command line are reported, while hand-written code can just misparse the input. In addition, the usage message can be automatically generated, to avoid falling out of sync with the real list of options.
  • Options can be read from anywhere. Sooner or later the command line will be not enough for your users, and you'll want config files or maybe even environment variables. These can be added without significant effort on your part.
381 questions
6
votes
1 answer

boost::program_options gives malloc error

I have the following toy program that gives errors with the MacPorts gcc on OSX 10.6 #include namespace po = boost::program_options; #include using namespace std; int main(int ac, char* av[]) { …
highBandWidth
  • 16,751
  • 20
  • 84
  • 131
6
votes
1 answer

boost::program_options and multiple sections in ini-file

I'm trying to get boost::program_options to read a ini file with multiple sections: [slave] address=localhost port=1111 [slave] address=192.168.0.1 port=2222 Is there any solution? Thanks in advance!
user1587451
  • 978
  • 3
  • 15
  • 30
6
votes
1 answer

How to handle unsolicited parameters in boost::program_options

I use boost::program_options to provide command line parsing interface to my application. I would like to configure it to parse the options, using namespace boost::program_options; options_description desc("Allowed options"); desc.add_options() …
user267885
5
votes
2 answers

boost::program_options how to reload a value

I would like to reload some values from a configuration file. I know that po::store will not change values if they exist in the variables_map. Is there an alternative that does replace values even if they already exist? I tried deleting values that…
sjcomp
  • 177
  • 2
  • 9
5
votes
1 answer

How to have an option enabling other options in Boost Program Options without using variables?

I use program options to parse the command line options of my application. I have several options like -Ox, -Oy, -Oz, ... and I want to have a super option -Oall that enables Ox and Oy and another -Osub that enables Oz and Ow. Is there a way to do…
Baptiste Wicht
  • 7,472
  • 7
  • 45
  • 110
5
votes
1 answer

Better handling of missing/wrong key in boost::program_options

Is there a way to know which key was involved when a call like the following fails ? boost::program_options::variables_map vm; ... int foo_bar = vm["some_key"].as(); If the key is missing from the map, or is not convertible to int, I get a…
Marco Righele
  • 2,702
  • 3
  • 23
  • 23
5
votes
1 answer

boolean options from boost program options

I am using boost program options to get boolean values from command line argument. I would like my argument to be specified as "Y", Yes", "N", "No". Actually my code did it using a temporary string that will be parsed by boost program…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
5
votes
2 answers

boost::program_options - does it do an exact string matching for command line options?

There seems to be a problem the way boost::program_options's options_description matching is done. int main(int argc, char* argv[]) { boost::program_options::options_description desc("CmdLine utility"); desc.add_options() ("hel",…
5
votes
1 answer

C++: Boost program_options: Multiple lists of arguments

I'm currently working with boost::program_options. My program is supposed to take as arguments (amongst other things...) an arbitrary number of 'lists' of arbitrary length. For example, the user should be able to call ./myprogram -list item1 item2…
DerAuenlaender
  • 139
  • 2
  • 6
5
votes
2 answers

boost program_options accept all values after last flag

Is there a way to collect all of the values after a specified argument with boost::program_options? There are two caveats that I need to take care of though, I need to accept unrecognized arguments, and I need to accept values that could contain…
sfpiano
  • 51
  • 2
5
votes
3 answers

Boost Program Options bool always True

With program options, I am checking valid combinations of arguments. But for some reason, gpu argument is a bool and it is always true regardless if I set it to false on the command line. Is there a way that gpu option can be false if I specified it…
Moeiz Riaz
  • 165
  • 2
  • 18
5
votes
0 answers

Mutually exclusive option groups

I'm getting familiar with boost's program options utility and I'm wondering is there a way of defining mutually exclusive option groups. I.e., my program has different flows: program --first --opt1 --opt2 ... program --second --opt3 --opt4…
Heghine
  • 435
  • 3
  • 15
5
votes
1 answer

Boost.Program_options fixed number of tokens

Boost.Program_options provides a facility to pass multiple tokens via command line arguments as follows: std::vector nums; po::options_description desc("Allowed options"); desc.add_options() ("help", "Produce help message.") …
kloffy
  • 2,928
  • 2
  • 25
  • 34
5
votes
1 answer

Boost program options: positional and multitoken options

How does boost::program_options parse or manage an input when both multitoken and positional options are allowed? For example: ./app.sample pos1 --multitokenoption a b c d pos2 How does boost know when a multitokenoption finishes and a positional…
ABu
  • 10,423
  • 6
  • 52
  • 103
5
votes
2 answers

Multiple repeated sections in a config file

I've a config file format I was hoping to implement with Boost Program Options (as I've used that library before), but I somehow have to implement blocks like this: label = whatever depth = 3 start source = /etc dest = /tmp/etc/ end start source =…
Darren Cook
  • 27,837
  • 13
  • 117
  • 217