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
11
votes
1 answer

Boost Program Options won't work with GLIBCXX_DEBUG

I have the following sample code: #include #include int main ( int ac, char *av[] ) { // Declare the supported options. boost::program_options::options_description desc("Allowed options"); …
Haatschii
  • 9,021
  • 10
  • 58
  • 95
11
votes
2 answers

Limit the precision on std::cout of default values in boost::options_description

When I construct a boost::options_description instance like options.add_options() ("double_val", value(&config.my_double)->default_value(0.2), "it's a double"); and later want to have the automated output of the options that are available for my…
Christian
  • 111
  • 3
11
votes
1 answer

Boost.Program_Options: When is specified as a command-line option, what are valid command-line parameters?

Given the following simple use of Boost.Program_Options: boost::program_options::options_description options("Options"); options.add_options() ("my_bool_flag,b", boost::program_options::value(), "Sample boolean switch)") ; ... what…
Dan Nissenbaum
  • 13,558
  • 21
  • 105
  • 181
11
votes
2 answers

boost::program_options: how to ignore unknown parameters?

In the boost::program_options library, I cannot understand how to allow the user to pass a parameter which has not been added through add_options(). I would like it to be just ignored, instead of terminating the program.
Pietro
  • 12,086
  • 26
  • 100
  • 193
10
votes
2 answers

How to get better error messages in Boost program options

In the code below, I used program options to read parameters from command-line or file. In addition, options can be set programatically at runtime through ConfigProxy::setConfig po::options_description desc("Allowed options"); desc.add_options() …
user1492900
  • 575
  • 1
  • 8
  • 16
10
votes
2 answers

Parsing LPTSTR* command line args with boost::program_options

I am having a problem with command line parsing with boost:program_options. The quickest way to explain it is to show the code so: const std::vector args; if (ac > 0 && NULL!=av) //ac is a ULONG { for (int i = 0; i < ac; i++) { …
Dennis
  • 3,683
  • 1
  • 21
  • 43
10
votes
2 answers

boost::program_options - how to handle multiple sections with the same name in INI file

In a config like below; is there a way to handle individual sections. I am looking for a way to validate individual "server" sections below, in a reliable manner. [basic] number_of_servers=3 [server] ip=10.20.30.40 password=sdfslkhf …
ϹοδεMεδιϲ
  • 2,790
  • 3
  • 33
  • 54
10
votes
1 answer

Default value for vector valued boost::program_options

I have a boost::program_options option that successfully parses the desired input options into a vector, but I'm not seeing how to also give it a default value. Example: base.add_options() ("vector_value",po::value
Aurelius
  • 1,146
  • 2
  • 13
  • 25
10
votes
1 answer

C++ boost::program_options reading arguments compatible with getopt_long

I'm developing an update in an existing program. I'm replacing Posix's getopt_long() with boost::program_options. But my work doesn't work as I should: I want to have read arguments like: -server=www.example.com -c config.txt I was trying many…
baziorek
  • 2,502
  • 2
  • 29
  • 43
9
votes
2 answers

Building boost::options from a string/boost::any map

I have a map which represents a configuration. It's a map of std::string and boost::any. This map is initialized at the start and I'd like the user to be able to override these options on the command line. What I'd love to do is build the program…
Moo-Juice
  • 38,257
  • 10
  • 78
  • 128
9
votes
1 answer

Serializing a variables_map

How do I serialize/deserialize a boost::program_options::variables_map? I can't find an already implemented serialize function, and I don't know what functions in variables_map I can use to extract and reassemble the map.
Jayen
  • 5,653
  • 2
  • 44
  • 65
9
votes
1 answer

Boost: unrecognised option for positional argument

I'm trying to parse command line with boost 1.58.0. My code is quite simple and copy\pasted from the tutorials. It looks like that: try { po::options_description desc; desc.add_options() ("version,v", "Display…
truf
  • 2,843
  • 26
  • 39
9
votes
1 answer

How do I use boost options_description with hexadecimal input?

I want to have two options for the program to work on, the start address and end address so that the program options are as follows: --start_address 0xc0000000 --end_address 0xffffffff Is it possible for options_description to take such hex input?…
dubnde
  • 4,359
  • 9
  • 43
  • 63
9
votes
2 answers

How does boost program_options work?

The weird thing to me is, that boost's options_description uses multi-line code without backslash or semicolon or comma. I did a little research, but found nothing. (Code taken from official boost's tutorial): int opt; po::options_description…
Jack L.
  • 1,257
  • 2
  • 17
  • 37
9
votes
1 answer

boost::program_options hangs on the arm "sometimes"

Currently I am using boost::program_options to parse a configuration file on the BeagleBoard (ARM-based processor). My program is multi-threaded and linked against the boost 1.45 multithreaded libraries. My program just seems to hang when parsing…
Adam A.
  • 502
  • 1
  • 4
  • 12