ros中yaml文件读写的一种实现

来源:互联网 发布:天天特价9.9淘宝网 编辑:程序博客网 时间:2024/05/29 16:23

 核心代码如下,实现了读取某个yaml文件,增加某项,在输出到文件中的作用。

#include "yaml-cpp/yaml.h"


 double res;

  std::string str;
  std::ifstream fin("/home/robot/test.yaml");
  YAML::Node doc = YAML::Load(fin);
  doc["resolution"] >> res;
  doc["mytest"] = "g";
  doc["resolutiond"] >> str;
  ROS_INFO("resolution:%f,%d",res,doc.size());
  ROS_INFO("mytest:%s",str.c_str());
  std::ofstream fout("/home/robot/test1.yaml");

  fout << doc;


需要注意在CMakefile.txt中target_link_libraries中增加yaml-cpp库。

https://github.com/jbeder/yaml-cpp/wiki/Tutorial

未完待续...

0 0
原创粉丝点击