Boost program_options将多个配置文件解析结果存储到一个parsed_options中 [英] Boost program_options store multiple config file parse results into one parsed_options
本文介绍了Boost program_options将多个配置文件解析结果存储到一个parsed_options中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图解析命令行中提供的任意数量文件中的未注册选项.假设我有文件:
I'm trying to parse unregistered options in any number of files provided at command line. Let's say I have files:
configs0.ini
configs1.ini
configs2.ini
我想支持其中任何一个.
And I wanted to support any number of these.
我的代码(简体):
namespace po = boost::program_options;
po::options_description cmd_opts{"Options"};
po::options_description config_file_opts;
po::variables_map vm;
cmd_opts.add_options()
("help,h", "Help message")
("config_files", po::value<std::vector<std::string>>()->multitoken(), "Configuration files to get settings from")
po::parser.options(reg_config_file_opts).allow_unregistered();
po::store(parse_command_line(argc, argv, cmd_opts), vm);
config_files = vm["config_files"].as<std::vector<std::string>>();
po::parsed_options parsed_opts;
for(auto file : config_files) {
std::ifstream ifs(file, std::ifstream::in);
if(ifs.fail()) {
std::cerr << "Error opening config file: " << file << std::endl;
return false;
}
ifs.close();
<NEED HELP HERE>
parsed_opt.add(parse_config_file(ifs, reg_config_file_opts));
}
po::store(parsed_opts, vm);
parsed_options是否具有某种.add功能?
Does parsed_options have some sort of .add ability?
推荐答案
打印:
Cmdline opts
config_files={"a.cfg", "b.cfg", "c.cfg"}
Combined configs
bar_a={"bar_val_a"}
bar_b={"bar_val_b"}
bar_c={"bar_val_c"}
foo={"foo_val_a", "foo_val_b", "foo_val_c"}
这篇关于Boost program_options将多个配置文件解析结果存储到一个parsed_options中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文