I'm writing a C++ command line application for users that we will be used on various platforms. For this reason, I am writing using only stl. I'm wondering if stl has a nice way to parse input arguments similar to the getopt function used in unistd.h/getopt.h (as these are not platform independent to my knowledge). I've already thought of doing something like while/for loop and switch statements, but wondering if there something a bit more elegant. C++11 is ok, boost is not.
The solution to this is to write your own or use boost. As of C++11, there is no standard "getopt" functionality.
It's true that there isn't a way in standard C++ but getopt is a POSIX standard, which covers a lot of platforms (Linux, *NIX, *BSD, MacOS, iOS, Android, Cygwin).
On native Win32 simply embed something like wingetopt into your project (BSD-licensed). Also FreeBSD getopt.c can be easily ported (though it doesn't support long option format).
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