Is it possible to somehow use an option which selects a configuration file:
program --configuration-file my_config.conf
with the same easiness as common tasks demonstrated in examples?
Thank you.
-el
Yes, it's possible, and documented in the "multi-source" section as Sebastian already mentioned. The options_description that is used to parse the command line should contain an option for a configuration file: string configFileName; options_description optdesc("Options"); optdesc.add_options() // add whatever options you have, plus ("config", po::value< string >( &configFileName ), "The name of a file to read for default options. Command-line options" " override the ones in the config file. A config file may contain lines with syntax" "\n'long_option_name = value'\nand comment lines that begin with '#'." ) ; po::store(po::command_line_parser(argc,argv).options(optdesc).positional(popt).run(), varmap); po::notify( varmap ); if( varmap.count("config") ) { cout << "Trying to read options from " << configFileName << "..."; cout.flush(); ifstream ifs( configFileName.c_str() ); if( !ifs.is_open() ) cout << "no such file." << endl; else { po::store( po::parse_config_file( ifs, optdesc ), varmap ); po::notify( varmap ); cout << "done." << endl; } }