用yaml cpp解析yaml

时间:2015-09-10 03:00:21

标签: c++ yaml-cpp

我正在尝试解析yaml usign yaml-cpp。这是我的名字:

--- 
configuration: 
  - height: 600
  - widht:  800
  - velocity: 1
  - scroll: 30
types: 
  - image: resources/images/grass.png
    name: grass
  - image: resources/images/water.png
    name: water
 version: 1.0

当我这样做时

YAML::Node basenode = YAML::LoadFile("./path/to/file.yaml");
int height;
if(basenode["configuration"])
    if(basenode["configuration"]["height"]
       height = basenode["configuration"]["height"].as<int>();
    else
       cout << "The node height doesn't exist" << endl;
else
    cout << "The node configuration doesn't exist" <<  endl;

我收到消息:&#34;节点高度不存在&#34;。如何访问该字段(以及其他字段?)

非常感谢!

0 个答案:

没有答案