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
14
votes
3 answers

Accepting negative doubles with boost::program_options

I need to be able to have boost::program_options parse an array of doubles that are passed on a command line. For positive doubles, this is no problem, of course (use multitoken with std::vector in add_options), but for negative ones, I know…
Howard Butler
  • 243
  • 2
  • 7
14
votes
4 answers

boost::program_options : iterating over and printing all options

I have recently started to use boost::program_options and found it to be highly convenient. That said, there is one thing missing that I was unable to code myself in a good way: I would like to iterate over all options that have been collected in a…
shiin
  • 462
  • 6
  • 17
13
votes
2 answers

How do you manually insert options into boost.Program_options?

I have an application that uses Boost.Program_options to store and manage its configuration options. We are currently moving away from configuration files and using database loaded configuration instead. I've written an API that reads…
Alex
  • 6,843
  • 10
  • 52
  • 71
13
votes
3 answers

c++: program settings - boost.PropertyTree or boost.program_options?

I was looking for a solution to store program settings or options or configuration in C++. These could be settings that are exposed in a GUI and need to be saved between runs of my code. In my search I came across boost.PropertyTree which seemed to…
User
  • 62,498
  • 72
  • 186
  • 247
13
votes
1 answer

Parsing positional arguments

Consider the following trivial program adopted from the boost program options examples #include #include #include int main( int argc, char** argv ) { namespace po =…
Sam Miller
  • 23,808
  • 4
  • 67
  • 87
13
votes
3 answers

Boost parse_config_file, empty key value

I am using Boost program_options to parse a config file in the standard way as shown in the multiple_sources.cpp example file of program_options. ifstream ini_file("config.ini"); po::store(po::parse_config_file(ini_file, desc, true),…
Ess Gee
  • 131
  • 1
  • 4
13
votes
1 answer

Want to allow options to be specified multiple times when using boost program options. Right now I get multiple occurrences

I am using boost program_options 1.50.0 I want to ALLOW the following for my program foobar foobar --debug 2 --debug 3 From the boost program_options code, there is an example regex.cpp that shows creating a new type and creating a validator for…
Matt Frazer
  • 177
  • 1
  • 7
13
votes
1 answer

How do I specify a default value for vector in boost::program_options

I do want to give a default value for the positional parameter as in the comment in the code, but the compiler complains. The code as it is compiles fine. I use boost 1.46.1 and g++ int main(int argc, char *argv[]) { namespace po =…
Michael
  • 1,464
  • 1
  • 20
  • 40
12
votes
1 answer

How to add a description to boost::program_options' positional options?

I would like to make a positional, list program option with boost_program_options that do not allow named program options (like --files). I have the following snippet of code: #include #include #include…
Patryk
  • 22,602
  • 44
  • 128
  • 244
12
votes
2 answers

boost::program_options positional options

I have a positional option (a file name), and I want it to be the very last option. The user can pass in a bunch of stuff on the command line, and also use -F for the file name. However, I want the user also to have the ability to place the file…
It'sPete
  • 5,083
  • 8
  • 39
  • 72
12
votes
2 answers

boost::program_options bug or feature?

Very simple example: #include #include namespace po = boost::program_options; int main(int argc, char* argv[]) { po::options_description recipients("Recipient(s)"); recipients.add_options() …
Dmitriy
  • 3,305
  • 7
  • 44
  • 55
12
votes
3 answers

BOOST program_options: parsing multiple argument list

I would like to pass the multiple arguments with positive or negative values. Is it possible to parse it? Currently I have a following initialization: vector IDlist; namespace po = boost::program_options; po::options_description…
Arman
  • 4,566
  • 10
  • 45
  • 66
12
votes
3 answers

How to accept empty value in boost::program_options

I'm using boost::program_options library to process command line params. I need to accept a file name via -r option, in case if it is empty (-r given without params) I need to use stdin. desc.add_options() ("replay,r",…
cppalex
  • 537
  • 4
  • 11
11
votes
1 answer

In Boost::Program_Options, how to set default value for wstring?

My code below did not work: wstring config_file; // Declare a group of options that will be // allowed only on command line po::options_description generic("Generic options"); generic.add_options() ("help,h", "produce help message") …
MQ Gu
  • 643
  • 2
  • 9
  • 19
11
votes
1 answer

Boost Program Options dependent options

Is there any way of making program options dependent on other options using boost::program_options? For example, my program can accept the following sample arguments: wifi --scan --interface=en0 wifi --scan --interface=en0 --ssid=network wifi…
Conor Taylor
  • 2,998
  • 7
  • 37
  • 69
1 2
3
25 26