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

Echo entered command line parameters in Boost

I am using boost::program_options to parse command line parameters. I would like my program to echo the entered parameters back to the user for verification. This sounds like a simple task but I was unable to find an elegant solution. The problem is…
Compuholic
  • 388
  • 4
  • 14
1
vote
1 answer

Why can't I use the << operator with the value extracted from this variables_map?

I'm familiarizing myself with boost::program_options (and C++ in general). I wrote the function below, but I can't quite understand the error I'm getting. Here's the code (note that po is an alias for boost::program_options). int…
Louis Thibault
  • 20,240
  • 25
  • 83
  • 152
1
vote
1 answer

Why is this use of the [] operator causing a compiler error?

I wrote this quick function to get familiar with boost::program_options. Please note that po is a namespace alias, defined thus: namespace po = boost::program_options. int application(po::variables_map* vm) { std::cout << vm << std::endl; …
Louis Thibault
  • 20,240
  • 25
  • 83
  • 152
1
vote
0 answers

How can the boost program options library be used to parse a config file with repeated sections?

How can a file like this be parsed, especially in the Devices section? Also, does boost handle the input stream, or does that have be handled by additional code? [Configuration] IPAddress=192.168.1.1 Device Port=12345 Management Port =…
bentaisan
  • 1,056
  • 3
  • 12
  • 29
1
vote
1 answer

boost::program_options crashes on help when implicit_value used somewhere else

I have the following code snippet to accept runtime program options. Everything works well as long as I don't have --help on the command line. On invoking --help I receive malloc: * error for object 0x7fff7b646570: pointer being freed was not…
Nikhil J Joshi
  • 1,177
  • 2
  • 12
  • 25
1
vote
2 answers

Compiling program with CMake and Boost - compiles and links, but bad output and segfaults when run

I'm having an issue when compiling a program with CMake 2.8.9 and Boost 1.49, on Ubuntu 12.10 (libboost installed via repos). Currently, the program is just some shared libs and an executable (which doesn't use the libs yet). The executable uses…
Inductiveload
  • 6,094
  • 4
  • 29
  • 55
1
vote
1 answer

Get a string from the command line when using boost program_options

I am using the boost program_options library to process command line and configuration file data, but it is not clear to me how to get the required string from the processed data. How do I get the program_options command line parameters into the…
bentaisan
  • 1,056
  • 3
  • 12
  • 29
1
vote
1 answer

parse custom objects through config file/command line using boost program options

So I have just started adding option support to my code. I can either do it myself or use boost's program options. The only thing that holds me back from using boost's is yet another dependency that I'm adding to the project. However, if it can…
mmirzadeh
  • 6,893
  • 8
  • 36
  • 47
1
vote
2 answers

Boost Program Options optional argument precedence

The application has two options: a and file. file is a positional option. Both a and file have an argument of type string, which can be omitted. (I have set an implicit empty string for both). The desired behaviour is as follows: $ program -> file:…
Ruud
  • 3,118
  • 3
  • 39
  • 51
1
vote
1 answer

How to handle multiple syntax command line arguments using boost.program_options

Consider a utility which can be used in different modes, like: utility.exe --mode x (one list of arguments expected) utility.exe --mode y (different list of arguments expected) How can i write code for parsing such arguments in…
anni
  • 338
  • 2
  • 12
0
votes
0 answers

Get pointer to argv element Boost Program Options

I'm making the assumption that the array of strings passed into the main function as argv in void main( int argc, char* argv[] ) remains in scope for the duration of the application. My question is therefore whether it is possible, using…
Nick
  • 25,026
  • 7
  • 51
  • 83
0
votes
1 answer

Boost.program_options silently fails only after adding positional option to the parser

I am trying to use Boost.program_options, but positional arguments do not work. I am a newbie at this. #include "Application.h" #include #include #include #include #include #include…
Generic
  • 1
  • 2
0
votes
0 answers

Provide examples on how to run program in "help"

How can I provide some examples on how to use the different boost program options at the end of my help message? I know I can add descriptions with options_description but how can I add a few options at the end of the help?
user1618465
  • 1,813
  • 2
  • 32
  • 58
0
votes
1 answer

boost::program_options option of type std::optional will not compile

The line attempting to add_options() of type std::optional results in a compile error. does boost::program_options not support this type? how are optional options managed w/ boost::program_options? #include #include…
0
votes
2 answers

Program can't find libboost_program_options.so.1.47.0 at runtime

Since I don't have root permission to install Boost C++ library, I installed it under my home local. When compiling, I used: g++ -I/home/name/local/boost_1_47_0 -L/home/name/local/boost_1_47_0/stage/lib foo.cc -o foo -lboost_program_options but at…
JDai
  • 13
  • 2
  • 6