Created
May 31, 2014 12:58
-
-
Save denkiwakame/149bdd84b47d70151bbf to your computer and use it in GitHub Desktop.
boost::program_options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/program_options.hpp> | |
#include <iostream> | |
int main(int argc, char const* argv[]) | |
{ | |
// add options | |
boost::program_options::options_description cmdline("Command line options"); | |
cmdline.add_options() | |
("help,h", "show help message") | |
("list", "list available cameras") | |
("shutter,s", boost::program_options::value<int>()->default_value(10), "shutter speed"); | |
boost::program_options::variables_map values; | |
try { | |
// parse_command_line and store into variables_map | |
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, cmdline), values); | |
std::cerr << values["shutter"].as<int>() << std::endl; | |
const int shutter_speed = values["shutter"].as<int>(); | |
} catch (std::exception &e) { | |
std::cerr << e.what() << std::endl; | |
} | |
// show full options | |
std::cerr << cmdline << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment