Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which library to use to parse command line arguments in C++ [closed]

I know about getopts and argp. I just looked in boost and they have program_options as a library for parsing command-line parameters.

I'm not exactly sure which one to use. I know getopts is POSIX, while argp isn't but that doesn't matter to me. What matters is ease of use. Can you recommend (pros/cons?) one. I'm open to other libraries too.

like image 725
s5s Avatar asked Apr 15 '12 08:04

s5s


People also ask

How do you pass command line arguments in C?

To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments. The value of argc should be non negative. argv(ARGument Vector) is array of character pointers listing all the arguments.

Which is used to handle command line arguments?

Command-line Argument Processing. On most UNIX platforms, command-line argument processing is handled using the getopt function. This function parses arguments passed to a program via the command line, with each option and possible argument made available to the programmer via a switch statement.

Which module do we use for command line arguments?

Python sys module stores the command line arguments into a list, we can access it using sys. argv . This is very useful and simple way to read command line arguments as String.


2 Answers

If you want something lightweight and easy to use, then you might be interested in TCLAP (header only, liberal license). (example)

Otherwise boost::program_options (also liberal license) provides virtually anything one could need. (example)

Finally if you are already using a framework/library (WxWidgets, Qt) that has some command-line argument handling then probably the simplest option is to stick with that framework.

like image 145
Anonymous Avatar answered Oct 21 '22 04:10

Anonymous


You could also use popt.

If you are using a graphical toolkit like Gtk (thru GtkMM if in C++) or Qt, each of these offer their own command line arguments parsing facilities.

like image 23
Basile Starynkevitch Avatar answered Oct 21 '22 05:10

Basile Starynkevitch