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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With