views:

1431

answers:

7

I'd like to pass parameters to my C++ program in the following manner:

./myprog --setting=value

Are there any libraries which will help me to do this easily?

See also http://stackoverflow.com/questions/189972/argument-parsing-helpers-for-c-unix/191821

+19  A: 

Boost.Program_options

Igor Semenov
+10  A: 

GNU GetOpt.

Marcin Gil
+3  A: 

There are these tools in the GNU C Library, which includes GetOpt.

If you are using Qt and like the GetOpt interface, froglogic has published a nice interface here.

Dusty Campbell
+3  A: 

argstream is quite similar to boost.program_option: it permits to bind variables to options, etc. However it does not handle options stored in a configuration file.

Luc Hermitte
+4  A: 

And there's a Google library available.

Really, command-line parsing is "solved." Just pick one.

Max Lybbert
A: 

There are a couples of C++ argument parsers out there, you may want to try this one from http://clp.sourceforge.net/, very simple and convenient.

ectasy
A: 

Try CLPP library. It's simple and flexible library for command line parameters parsing. Header-only and cross-platform. Uses ISO C++ and Boost C++ libraries only. IMHO it is easier than Boost.Program_options.

Library: http://sourceforge.net/projects/clp-parser/

26 October 2010 - new release 2.0rc. Many bugs fixed, full refactoring of the source code, documentation, examples and comments have been corrected.

Denis Shevchenko