Using program_options from a string?

Hello all. I am using the boost::program_options library for configuration files with great success. I'm wondering if it's possible to use the library using a string as a source, instead of a config file. I read the configuration file with code like this: if (vm.count("config")) { string f = vm["config"].as<string>() ; ifstream ifs(f.c_str()); store(parse_config_file(ifs, config_file_options), vm); po::notify(vm); } but what I'd also like to do is something along these lines, with a string as the original source instead of a file specified with my 'config' command line option: string str = "port = 3000 \n tmpdir = /tmp \n"; // something like this. this is what's in the config file. istringstream iss(str, istringstream::in); store(parse_config_file(iss, config_file_options), vm); po::notify(vm); These lines compile and execute without error but don't actually appear to update the 'vm'. Am I doing something wrong or is this not possible with the current incarnation of program_options? Thanks! -- View this message in context: http://www.nabble.com/Using-program_options-from-a-string--tp22405416p224054... Sent from the Boost - Users mailing list archive at Nabble.com.

boostnewbie wrote:
Hello all. I am using the boost::program_options library for configuration files with great success. I'm wondering if it's possible to use the library using a string as a source, instead of a config file.
I read the configuration file with code like this: if (vm.count("config")) { string f = vm["config"].as<string>() ; ifstream ifs(f.c_str()); store(parse_config_file(ifs, config_file_options), vm); po::notify(vm); }
but what I'd also like to do is something along these lines, with a string as the original source instead of a file specified with my 'config' command line option:
string str = "port = 3000 \n tmpdir = /tmp \n"; // something like this. this is what's in the config file. istringstream iss(str, istringstream::in); store(parse_config_file(iss, config_file_options), vm); po::notify(vm);
These lines compile and execute without error but don't actually appear to update the 'vm'. Am I doing something wrong or is this not possible with the current incarnation of program_options?
This should be possible. You might want to step into 'store' with a debugger to check if: - parse_config_file actually returns nothing, or - store fails to do anything, or - the problem is elsewhere. - Volodya
participants (2)
-
boostnewbie
-
Vladimir Prus