// 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) #include using namespace boost; namespace po = boost::program_options; #include #include #include using namespace std; // A helper function to simplify the main part. template ostream& operator<<(ostream& os, const vector& v) { copy(v.begin(), v.end(), ostream_iterator(cout, " ")); return os; } int main(int ac, char* av[]) { try { int opt; po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("optimization", po::value(&opt)->default_value(10), "optimization level") ("include-path,I", po::value< vector >(), "include path") ("input-file", po::value< vector >(), "input file") ; po::positional_options_description p; p.add("input-file", -1); po::variables_map vm; po::store(po::command_line_parser(ac, av). options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("help")) { cout << "Usage: options_description [options]\n"; cout << desc; return 0; } if (vm.count("include-path")) { cout << "Include paths are: " << vm["include-path"].as< vector >() << "\n"; } if (vm.count("input-file")) { cout << "Input files are: " << vm["input-file"].as< vector >() << "\n"; } cout << "Optimization level is " << opt << "\n"; } catch(exception& e) { cout << e.what() << "\n"; return 1; } return 0; }