2
我有一個以下格式的文件,我試圖使用boost :: property_tree :: read_ini和boost :: property_tree來解析。閱讀ini文件使用boost :: property_tree不與形式A.x的孩子工作
示例配置文件(有些值包含空格)
[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的孩子嗎?因此,我需要get_child B?