【发布时间】:2014-01-08 08:51:59
【问题描述】:
我有一个以下格式的文件,我正在尝试使用 boost::property_tree::read_ini 和 boost::property_tree 进行解析。
示例配置文件(某些值包含空格)
[Config]
A = 1000
B.x = Test
B.y = Test By
C.x.y = Test_Cxy
C.x.z = Test Cxz
[Config2]
...
示例代码
boost::property_tree::ptree config;
boost::property_tree::read_ini (name, config);
// Correctly Iterates through and displays correct pairs
for (ptree::const_iterator it = pt.begin(); it != end; ++it) {
std::cout << it->first << ": " << it->second.get_value<std::string>() << std::endl;
print(it->second);
}
const boost::property_tree::ptree& configTree = config.get_child("Config");
// Correctly gets A
std::string test_ = configTree.get<std::string>("A", "Default");
// Doesn't get B.x
std::string test_ = configTree.get<std::string>("B.x", "Default");
我做错了什么?如何正确获取 B.x、B.y 等?是不是 B.x 被视为 B 的孩子?因此我需要获取 B 的_child?
【问题讨论】:
标签: c++ boost boost-propertytree