This is yet another C++ version of the getopt function, that is, for parsing command line options and environment variables. However, unlike other versions, the design goals of this one are:
- EASY to use
- EASY to learn
- mimc STL's streams
- minimum code to type
- smooth integration with STL types
- Platform independant (ANSI C++)
- EASY to extend for your own types
That is, you just construct a GetOpt_pp object with argc and argv, and then extract the options with the >> operator as an istream :)
Example: We want to receive two options, one for an int (say, named -i and --test1), and another for a float (named -f and without long option). Results in test1 and test2 vars.
int main(int argc, char* argv[])
{
using namespace GetOpt;
int test1 = 10;
float test2 = 3.14f;
GetOpt_pp ops(argc, argv);
ops >> Option('i', "test1", test1) >> Option('f', test2);
std::cout << test1 << "\n" << test2 << "\n";
return 0;
}See the project's Wiki for documentation.
Current version: 2.13
Coming soon: environment stream for inserting and extracting env vars!
Don't miss GetOpt_pp Episode 3!
This project belongs to FuDePAN.