// Copyright Vladimir Prus 2002-2004. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) /* The simplest usage of the library. */ #include #include namespace po = boost::program_options; #include #include #include using namespace std; int main(int ac, char* av[]) { boost::any what; std::string a("hallo!"); what = a; std::string b = boost::any_cast(what); try { po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("compression", po::value(), "set compression level") ("log", po::value(), "set log file") ; 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("log")) { cout << "Logfile: " << vm["log"].as()<<".\n"; } if (vm.count("compression")) { cout << "Compression level was set to " << vm["compression"].as() << ".\n"; } else { cout << "Compression level was not set.\n"; } } catch(exception& e) { cerr << "error: " << e.what() << "\n"; return 1; } catch(...) { cerr << "Exception of unknown type!\n"; } return 0; }