tags:

views:

89

answers:

6

Is it bad form to use the GNU getopt in C++ programs? Is there a C++ specific alternative, or should I still just use getopt?

+2  A: 

In C++ you can also use boost::program_options.

codaddict
+3  A: 

I don't know that there's anything wrong with using getopt. But you might want to look at Boost.Program_options.

Fred Larson
+1  A: 

Not at all, getopt is perfectly fine in C++. The Boost::program_options require that the Boost library be installed, which many may not have.

greg
Boost can be built as static libraries. Otherwise, you'd practically have to ship the dynamic libs with your project *anyway*.
greyfade
I mean that the "devel" packages for many Linux distros may not include Boost by default.
greg
+1  A: 

Look at this: http://michael.dipperstein.com/optlist/index.html

muntoo
+4  A: 

There is nothing wrong with using getopt. There are a multitude of object oriented alternatives floating around including Boost.Program_options, and classes in POCO, and ACE.

Duck
+1 for boost program options.
thekidder
+1  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