| 1 | #include <iostream> | 
|---|
| 2 | using namespace std; | 
|---|
| 3 | #include <boost/program_options.hpp> | 
|---|
| 4 | namespace po = boost::program_options; | 
|---|
| 5 |  | 
|---|
| 6 | int main(int argc, char **argv) | 
|---|
| 7 | { | 
|---|
| 8 | po::options_description desc("Options"); | 
|---|
| 9 | desc.add_options() | 
|---|
| 10 | ("help", "this help screen") | 
|---|
| 11 | ("foo-1", po::value<int>(), "foo") | 
|---|
| 12 | ("bar-2", po::value<int>(), "bar") | 
|---|
| 13 | ; | 
|---|
| 14 | po::variables_map vm; | 
|---|
| 15 | po::store(po::parse_command_line(argc, argv, desc), vm); | 
|---|
| 16 | po::notify(vm); | 
|---|
| 17 | if (vm.count("help")) { | 
|---|
| 18 | cout << desc << "\n"; | 
|---|
| 19 | return 0; | 
|---|
| 20 | } | 
|---|
| 21 | cout << "count(foo-1)=" << vm.count("foo-1") << '\n' | 
|---|
| 22 | << "count(1)=" << vm.count("1") << '\n' | 
|---|
| 23 | << "count(bar-2)=" << vm.count("bar-2") << '\n'; | 
|---|
| 24 | return 0; | 
|---|
| 25 | } | 
|---|