【发布时间】:2016-09-21 20:55:30
【问题描述】:
我正在尝试解析以下 config.yaml 文件。
config.yaml
foo:
bar:
baz: [1, 2, 3, 4]
bam: "some_string_value"
test.cpp
YAML::Node configObj = YAML::LoadFile("cfig.yaml"); // loads file just fine
YAML::Node fooObj = configObj["foo"]; // this Node object is a Map
// iterate over foo node to get bar node
for( auto it = fooObj.begin(); it != fooObj.end(); ++it){
YAML::Node barMap = it->second; // this Node object is a Map
// iterate over bar node to get bad node
for( auto i = barMap.begin(); i != barMap.end(); ++i){
YAML::Node bazMap = i->second; // this node is a sequence
for( std::size_t i=0; i<bazMap.size(); i++
auto index = bazMap[i].as<int>(); // <<< This is the problem
}
}
}
据我所知,问题是我希望索引是一个 int 但bazMap[i].as<int>() 我希望第一个循环是 1,第二个循环是 2,等等。我得到的是 bazMap[i].as<int>()是地图类型。我在这里的理解中缺少什么?
谢谢,
布鲁斯
更新 答案是我在嵌套的 for 循环中很早就停止了。
【问题讨论】:
-
你解决了吗?如果是这样,您实际上可以在下面写一个答案并将其标记为“已接受”。
-
对不起,我正在度假。我做到了,我会的。谢谢!