Last change
on this file since 45 was
29,
checked in by landauf, 17 years ago
|
updated boost from 1_33_1 to 1_34_1
|
File size:
1.3 KB
|
Line | |
---|
1 | // Copyright Vladimir Prus 2002-2004. |
---|
2 | // Distributed under the Boost Software License, Version 1.0. |
---|
3 | // (See accompanying file LICENSE_1_0.txt |
---|
4 | // or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | |
---|
6 | /* The simplest usage of the library. |
---|
7 | */ |
---|
8 | |
---|
9 | #include <boost/program_options.hpp> |
---|
10 | namespace po = boost::program_options; |
---|
11 | |
---|
12 | #include <iostream> |
---|
13 | #include <iterator> |
---|
14 | using namespace std; |
---|
15 | |
---|
16 | int main(int ac, char* av[]) |
---|
17 | { |
---|
18 | try { |
---|
19 | |
---|
20 | po::options_description desc("Allowed options"); |
---|
21 | desc.add_options() |
---|
22 | ("help", "produce help message") |
---|
23 | ("compression", po::value<int>(), "set compression level") |
---|
24 | ; |
---|
25 | |
---|
26 | po::variables_map vm; |
---|
27 | po::store(po::parse_command_line(ac, av, desc), vm); |
---|
28 | po::notify(vm); |
---|
29 | |
---|
30 | if (vm.count("help")) { |
---|
31 | cout << desc << "\n"; |
---|
32 | return 1; |
---|
33 | } |
---|
34 | |
---|
35 | if (vm.count("compression")) { |
---|
36 | cout << "Compression level was set to " |
---|
37 | << vm["compression"].as<int>() << ".\n"; |
---|
38 | } else { |
---|
39 | cout << "Compression level was not set.\n"; |
---|
40 | } |
---|
41 | } |
---|
42 | catch(exception& e) { |
---|
43 | cerr << "error: " << e.what() << "\n"; |
---|
44 | return 1; |
---|
45 | } |
---|
46 | catch(...) { |
---|
47 | cerr << "Exception of unknown type!\n"; |
---|
48 | } |
---|
49 | |
---|
50 | return 0; |
---|
51 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.