Created
October 19, 2021 22:28
-
-
Save mostsignificant/e5ad1b02156e8497fa7da6fd6092e68b to your computer and use it in GitHub Desktop.
blog-boost-program-options-example
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
namespace po = boost::program_options; | |
// Declare the supported options. | |
po::options_description desc("Allowed options"); | |
desc.add_options() | |
("help", "produce help message") | |
("compression", po::value<int>(), "set compression level") | |
; | |
po::variables_map vm; | |
po::store(po::parse_command_line(ac, av, desc), vm); | |
po::notify(vm); | |
if (vm.count("help")) { | |
cout << desc << "\n"; | |
return 1; | |
} | |
if (vm.count("compression")) { | |
cout << "Compression level = " << vm["compression"].as<int>() << '\n'; | |
} else { | |
cout << "Compression level was not set.\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment