#include <boost/program_options.hpp> using namespace boost; using namespace boost::program_options; #include <iostream> using namespace std; int main(int ac, const char **av) { try { options_description desc("Allowed options"); desc.add_options() // First parameter is name, here, only long name is given // Second parameter is option's parameter -- none in this case // Third parameter is description ("help", "", "produce a help screen") // The first parameter specifies both long and short option names ("version,v", "", "print the version number") // This option has required parameter called "arg" ("string,s", "arg", "output the specified string") ; options_and_arguments oa = parse_command_line(ac, av, desc); if (oa.count("help")) { cout << "Usage: options_description [options]\n"; cout << desc; return 0; } if (oa.count("version")) { cout << "Version 1.\n"; return 0; } if (oa.count("string")) { cout << "The string is \"" << oa["string"] << "\"\n"; } } catch(exception& e) { cout << e.what() << "\n"; } }