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

How can I parse command line arguments that themselves contain switches using boost::program_options?

I'm writing a program in C++ that is a wrapper for some benchmarks that contains some setup code at the beginning and analisys code in the end. I want to run up to two benchmarks in parallel. The original commandlines for these…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
0
votes
1 answer

undefined reference boost::program_options::abstract_variables_map::operator[]

When I'm linking program_options to my shared library with: g++ -L/path_to_static_boost_libs -shared -o "test.so" ./test.o -lboost_program_options I can't load library because of undefined reference on…
Raman
  • 104
  • 2
  • 8
0
votes
1 answer

getting boost::program_options to treat input as const char* instead of std::string

class Foo {}; Foo foo; namespace po = boost::program_options; boost::program_options::options_description desc("Allowed options") desc.add_options() ("foo", po::value(&foo)); po::variables_map vm; po::store(po::parse_command_line(argc,…
MK.
  • 3,907
  • 5
  • 34
  • 46
-1
votes
1 answer

How to avoid a positional option to be specified as a "regular" option in boost::program_options?

According to the tutorial, it seems that every option has a name and can be specified as a regular option. Is it possible, to enforce an option to be only legal if specified as a positional option, and not show up in the help message as a regular…
xuhdev
  • 8,018
  • 2
  • 41
  • 69
-1
votes
3 answers

Program option library for portable code

I have a portable code running on Visual C++ 2008 and RHEL 5.3 (gcc 4.x.x). My program should accept command line arguments. I consider using some library for that task. My candidats are: Boost program options ACE has this capability too (1) is…
dimba
  • 26,717
  • 34
  • 141
  • 196
-2
votes
2 answers

Boost::Program_Options unhandled exception due to access violation

I have a program that runs fine in DEBUG mode but in RELEASE mode I get an unhandled exception due to an access violation. I'm pretty sure it's not due to null pointers. Here is the call stack: msvcr90d.dll!memchr(unsigned char * buf=0x0000002c,…
Dan
  • 842
  • 3
  • 17
  • 29
1 2 3
25
26