#include #include #include #include using namespace boost::program_options; using namespace std; int main(int argc, char *argv[]) { options_description opts; opts.add_options() ("cfgfile,c", value()->required(), "the configfile") ("fritz,f", value()->default_value("/other/file"), "the output file") ; variables_map vm; ifstream strm("options.ini"); try { store(parse_command_line(argc, argv, opts), vm); if (strm) { store(parse_config_file(strm, opts), vm); } notify(vm); } catch (required_option& e) { // new exception type cout << "required option: " << e.what() << endl; return -1; } catch (...) { cout << "other exception: " << endl; return -1; } cout << "count (cfgfile): " << vm.count("cfgfile") << endl; if (vm.count("cfgfile")) { cout << "is empty (cfgfile): " << (vm["cfgfile"].empty() ? "true": "false") << endl; cout << "value: " << vm["cfgfile"].as< string >() << endl; } return 0; }