source: box/nick/win/lib/win32/boost_1_32_0/libs/program_options/example/first.cpp @ 30

Last change on this file since 30 was 30, checked in by nick, 9 years ago

main core of the win32 work

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>
10namespace po = boost::program_options;
11
12#include <iostream>
13#include <iterator>
14using namespace std;
15
16int 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.