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
8
votes
2 answers

Using boost::program_options

In my program I have a list of pairs - name and size. I want to build this list from the command line interface using boost::program_options. It should look something like this: myProg --value("John",10) --value("Steve",14) --value("Marge",28) I…
8
votes
1 answer

boost program_options multiple values problem

So I'm working off one of the examples for Boost program_options library, and I wanted to try setting a default value for one of the multiple-values/ vector-values, but it doesn't seem to work. As I think is suggested here to work. What I've…
Petriborg
  • 2,940
  • 3
  • 28
  • 49
8
votes
3 answers

Boost program options setting min and max value for option

Is it possible to set minimum and maximum limit of a value (suppose it is unsigned short and I need a value between 0 and 10) as I can set default value by opt::value()->default_value(5) I want to use arguments given from variables…
VP.
  • 15,509
  • 17
  • 91
  • 161
8
votes
4 answers

Boost program options iterate over variables_map

po::options_description desc("This are the options that are available"); desc.add_options()("help", "print help")( "deer", po::value(), "set how many deer you want")( "rating", po::value(), "how good ?")( …
user2485710
  • 9,451
  • 13
  • 58
  • 102
8
votes
2 answers

Use Boost Program Options to parse an arbitrary string

I want to implement a command-line like interface inside my program. So I receive strings that follow the normal command-line syntax (e.g. "-G foo -dp bar --help"). As I don't want to implement the parser again, I would like to use Boost. The…
Netzdoktor
  • 526
  • 4
  • 15
8
votes
1 answer

boost::program_options: parameters with a fixed and a variable token?

Is it possible to use parameters of this kind with boost::program_options? program -p1 123 -p2 234 -p3 345 -p12 678 i.e., is it possible to specify the parameter name with a first token (e.g. -p) followed by a number, dynamically? I would like…
Pietro
  • 12,086
  • 26
  • 100
  • 193
7
votes
3 answers

How do I detect typo with Boost.program_options?

I use boost.program_options library. Consider this simplified case. po::options_description desc("Usage"); desc.add_options() ("uninstall,u", "uninstall program") ("custom,c", po::wvalue(), "specify custom action"); po::variables_map…
user10101
  • 1,704
  • 2
  • 20
  • 49
7
votes
2 answers

boost::program_options - parsing multiple command line arguments where some are strings including spaces and characters

I want to parse multiple command line arguments using boost::program_options. However, some arguments are strings enclosed in double quotes. This is what I have - void processCommands(int argc, char *argv[]) { std::vector
7
votes
3 answers

Boost Program_Options throws "character conversion failed"

I am on Ubuntu 14.04, using CMake and CLion. I am trying to use Program Options, with the following code taken from an example in their documentation: #include #include int main(int ac, char* av[]) { …
Victor
  • 13,914
  • 19
  • 78
  • 147
7
votes
1 answer

Can boost::program_options Use A Delimiter Other Than "-"?

I am using boost::program_options like this: namespace po = boost::program_options; po::options_description desc("Options"); desc.add_options() ("help,?", "Show Options") ("capture-file,I", po::value(), "Capture File") …
John Dibling
  • 99,718
  • 31
  • 186
  • 324
7
votes
1 answer

Parameters with and without arguments in boost::program_options

I wrote a small app that uses boost::program_options for command-line parsing. I'd like to have some options that set a value if the argument is present, and alternately prints the current value if the parameter is given but no argument is present.…
tmatth
  • 499
  • 4
  • 14
7
votes
1 answer

Does boost::program_options support requiring one of a series of alternatives?

I'm using the boost::program_options to specify the arguments to my C++ application. Is there a way to specify that one argument is required from a set of alternatives? [--one int-value1 | --two string-value2 | --three] In the above,…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
7
votes
1 answer

Boost Program_options config file comments

I have a program that reads a large number of variables from a configuration file using boost::program_options. The configuration file is working and reading the values, however since there are many options in the file, I would like to document…
Godric Seer
  • 359
  • 4
  • 16
7
votes
1 answer

boost program options: does custom validator require overloading operator>>?

In the example (regex.cpp), the author of the library created a custom struct (magic_number) and a validate function for this struct to show how custom struct can be integrated into program options. I followed his example to create a validate…
Candy Chiu
  • 6,579
  • 9
  • 48
  • 69
7
votes
2 answers

Grouping boost::program_options together into mandatory groups

I am using boost::program_options to handle command line parameters to a program. In the program below I would like group algo, exchanges and admin_port together such that they should all be provided else an exception is thrown (i.e. the don't make…
Graeme
  • 4,514
  • 5
  • 43
  • 71