Boost logo

Boost Users :

Subject: [Boost-users] Using program_options from a string?
From: boostnewbie (saabophile2_at_[hidden])
Date: 2009-03-08 21:36:06

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);

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);

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?


View this message in context:
Sent from the Boost - Users mailing list archive at

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at