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
1
vote
1 answer

Why does boost::program_options throw an error about a required argument when the default is defined

This is my code: #include #include #include "boost/program_options.hpp" namespace po = boost::program_options; int main(int argc, char *argv[]) { po::options_description cli_opts_desc("General flags"); …
Nic
  • 6,211
  • 10
  • 46
  • 69
1
vote
1 answer

add key value pairs in program options

I need to load a map inside my program, with an integer key and a string value, like this: 1, oil 2, car 5, house I want to load them using boost::program_options. I can see in the tutorial that I can load a vector from options with a syntax like…
Jepessen
  • 11,744
  • 14
  • 82
  • 149
1
vote
1 answer

Define global const variables known at run-time with helper functions (c++)

I want to define a series of global variables from within a parametrise() helper function like this: // helper.h namespace settings { extern const unsigned short something; } namespace helper { void parametrise(int, char**); // parametrise from…
Marinos K
  • 1,779
  • 16
  • 39
1
vote
1 answer

Undefined reference when linking with Boost using g++-4.9 on a g++-5-ish distribution

I've written the following groundbreaking application: #include int main(int argc, char** argv) { boost::program_options::options_description generic_options("foo"); return 0; } I am trying to build this on…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
1 answer

Boost.Program_options - free value (value without an option)

I need to use following syntax for a program: myprogram config.ini --option1 value --option2 value2 I'm using something like following: namespace po = boost::program_options; po::options_description desc("Allowed options"); …
vladon
  • 8,158
  • 2
  • 47
  • 91
1
vote
1 answer

Type un-erasure from a boost::program_options value

I'm trying to retrofit my program with boost::program_options. Among other things, I've written a function which I just can't get to compile. Here's a sort-of-minimal .cpp file which fails compilation: #include template…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
1 answer

how to validate file extension using boost::progam_option and boost::command_line_Parser

I am writing a program that uses Boost's Program Options library, I am not able to validate file extension using boost::program option: po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help…
Arif_Khan
  • 31
  • 4
1
vote
1 answer

"Multiple occurrences" exception for boost program_options

I am writing the following code on boost's program_options (version 1.42). This seems straight-forward and taken pretty much as is from the tutorial. However, I get a "multiple_occurrences" error. Further investigation discovers that it's (probably)…
R S
  • 11,359
  • 10
  • 43
  • 50
1
vote
1 answer

allow multiple occurrences of custom type using Boost::program_options

Is there any way I can allow multiple occurrences of custom type (struct) in boost::program_options? I found the various sources specifying this can be done using std::vector but I wanted to achieve the same using custom data type. However this…
Pranav
  • 560
  • 1
  • 8
  • 21
1
vote
1 answer

boost program options name for values

my goal is to create a program which can handle arguments like this: myProgram -i my_int=20 -s my_string=foo -f my_float=3.1415 Progress my current programm can be executed like this: myProgram -i 10 12 2 -s foobar anotherstring -f 3.1425…
YvesHendseth
  • 1,149
  • 1
  • 10
  • 27
1
vote
1 answer

boost::Program_options How to support hash character in a value?

I am trying to have the hash sign ('#') in a value of a configuration file. My use case is a music program in which the values give the tuning of a guitar score. Therefore, supporting '#' in the values is mandatory and supports no workaround, unlike…
AbVog
  • 1,435
  • 22
  • 35
1
vote
1 answer

Can I use Catch with boost/program_options.hpp?

I have a program that uses boost/program_options.hpp to process command line arguments. I want to add unit-tests to this program, and the Catch framework is very attractive. However, it seems to mess with the command line arguments to my…
a06e
  • 18,594
  • 33
  • 93
  • 169
1
vote
1 answer

Allow limited number of possibilities for a option in boost program_options

Can I tell boost program_options somehow, that a specific options has a limited number of values? For example, the option "--verbosity" may only be debug,high or low?!? Thanks! Nathan
Nathan
  • 515
  • 2
  • 7
  • 14
1
vote
0 answers

What's the proper way to set individual options with boost program_options?

I want to set an individual option with the boost::program_options library. The documentation doesn't seem to cover this. The variables_map structure the library populates inherits a map, so adding the following to my program (seems to)…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
1 answer

boost::program_options appends vector options with similar names

I'm using program_options to parse commandLine and configuration options and I found what seems to be a bug. The problem appears when using vector options with similar names. If I have an unspecified parameter "myParam" and another specified…
MAB
  • 117
  • 2
  • 13