conditional config file loading using boost::program_options
for example, I have a config file like this:
1 2 3 4 5 6 7 8 9 10 11
|
num = 2
[a0]
x = 0
y = 1
z = 2
[a1]
x = 0
y = 1
z = 2
|
if num = 3, another group a3 will be appended after the config file.
How can I read this file using boost::program_options?
I've tried this code using exception,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
fstream file("config.txt", fstream::in);
boost::program_options::options_description desc;
boost::program_options::variables_map vm;
try {
desc.add_options()
("num", boost::program_options::value<int>(&num), "number")
;
boost::program_options::store(boost::program_options::parse_config_file(file, desc), vm):
}
catch (exception& e) {
int num;
if (vm.count("num")) {
num = vm["num"].as<int>();
for (int i = 0; i < num; i++)
// desc options a0, a1, a2, ... adding
store again
.......
}
|
however, store() didn't store the loaded parameters in vm when unknown options are found in the file.
Please help!
Topic archived. No new replies allowed.