C++ 如何使用yaml cpp解析文件

C++ 如何使用yaml cpp解析文件,c++,parsing,dictionary,yaml,yaml-cpp,C++,Parsing,Dictionary,Yaml,Yaml Cpp,我有一个yaml文件,如下所示: construction_cone_1: model: construction_cone model_type: sdf position: [ 1.2, 3.4, 0.0 ] orientation: [ 0.0, 0.0, 0 ] construction_cone_2: model: construction_cone model_type: sdf position: [ 3.0, 7.0, 0.0 ] orien

我有一个yaml文件,如下所示:

construction_cone_1:
  model: construction_cone
  model_type: sdf
  position: [ 1.2, 3.4, 0.0 ]
  orientation: [ 0.0, 0.0, 0 ]
  
construction_cone_2:
  model: construction_cone
  model_type: sdf
  position: [ 3.0, 7.0, 0.0 ]
  orientation: [ 0.0, 0.0, 0 ]
 
...

我在教程中分析它在C++应用程序中的用法。 到目前为止,我所理解的是,由于它是结构化的,所以文件作为映射加载到

YAML::Node
中。因此,我想,阅读它的一个好方法是:

YAML::Node map = YAML::LoadFile(file_path);
  for(YAML::const_iterator it=map.begin(); it!=map.end(); ++it){
    const std::string &key=it->first.as<std::string>();
YAML::Node map=YAML::LoadFile(文件路径);
for(YAML::const_迭代器it=map.begin();it!=map.end();++it){
const std::string&key=it->first.as();

这为我的第一个条目提供了“construction\u cone\u 1”,以此类推。按照这种逻辑,我无法理解如何读取其余的条目。特别是,对于地图的每个条目,我都对读取对象位置感兴趣。

我想我低估了库的功能。这样做可以解决问题:

  YAML::Node map = YAML::LoadFile(filename);
  for(YAML::const_iterator it=map.begin(); it!=map.end(); ++it){
    const std::string &key=it->first.as<std::string>();

    Eigen::Vector2f pos;
    YAML::Node attributes = it->second;
    YAML::Node position = attributes["position"];
    for(int i=0; i<2; ++i){
      pos(i) = position[i].as<float>();
    }

    ...
  }
YAML::Node map=YAML::LoadFile(文件名);
for(YAML::const_迭代器it=map.begin();it!=map.end();++it){
const std::string&key=it->first.as();
本征::矢量2f位置;
YAML::Node attributes=it->second;
YAML::节点位置=属性[“位置”];
对于(int i=0;i