小编Kri*_*lay的帖子

用yaml cpp解析yaml

我正在尝试解析yaml usign yaml-cpp.这是我的yaml:

--- 
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
Run Code Online (Sandbox Code Playgroud)

当我做

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;
Run Code Online (Sandbox Code Playgroud)

我收到消息:"节点高度不存在".我如何访问该字段(以及其他字段?)

非常感谢!

c++ yaml-cpp

6
推荐指数
1
解决办法
3006
查看次数

标签 统计

c++ ×1

yaml-cpp ×1