在yaml-cpp中读取地图

Reading maps in yaml-cpp

本文关键字:地图 读取 yaml-cpp      更新时间:2023-10-16

我有以下yaml文件:

Pantalla:
ancho: 640
alto: 480
Configuracion:
    vel_personaje: 3
    merge_scroll: 30
Tipos:
    - nombre: arbol
      imagen: img/tree
      ancho_base: 2
      alto_base: 2
      pixel_ref_x: 30
      pixel_ref_y: 40
      fps: 10
      delay: 5
    - nombre: casa
      imagen: img/house
    - nombre: auto
      imagen: img/car
      ancho_base: 5
      alto_base: 5
Escenario:
    - nombre: principal
      size_x: 100
      size_y: 100
      entidades:  
           ­- {x: 10, y: 15, tipo: tierra}
           ­- {x: 15, y: 20, tipo: tierra}
           ­- {x: 10, y: 15, tipo: agua} 
         ­  - {x: 30, y: 55, tipo: castillo}
    protagonista:
        - tipo: principal
          x: 50
          y: 50

当我试图读取不同的"entidades"时,yaml-cpp显示如下:

抛出'YAML::ParserException'实例后调用终止What (): yaml-cpp:第32行第25列错误:非法映射值

第32行第25列正好在"y: "后面。我不知道我做错了什么。谢谢你的帮助!

第28行破折号为u00ad,即"软连字符"。我觉得应该是这样的:

Escenario:
    nombre: principal
    size_x: 100
    size_y: 100
    entidades:  
        ­- {x: 10, y: 15, tipo: tierra}
    ­    - {x: 15, y: 20, tipo: tierra}
    ­    - {x: 10, y: 15, tipo: agua}
    ­    - {x: 30, y: 55, tipo: castillo}
    protagonista:
        - tipo: principal
          x: 50
          y: 50
          y: 50