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?
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?
I find it easier to use ezOptionParser. It's also a single header file, does not depend on anything but STL, works for Windows and Linux (very likely other platforms too), has no learning curve thanks to the examples, has features other libraries don't (like file import/export with comments, arbitrary option names with delimiters, auto usage formatting, etc), and is LGPL licensed.
Qt 5.2 comes with a command line parser API.
Small example:
Example output
The automatically generated help screen:
Automatically generated version output:
Some real calls:
A parse error:
Conclusion
If your program already use the Qt (>= 5.2) libraries, its command line parsing API is convenient enough to get the job done.
Be aware that builtin Qt options are consumed by
QApplication
before the option parser runs.TCLAP
is a really nice lightweight design and easy to use: http://tclap.sourceforge.net/And there's a Google library available.
Really, command-line parsing is "solved." Just pick one.
argstream
is quite similar toboost.program_option
: it permits to bind variables to options, etc. However it does not handle options stored in a configuration file.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.