I already have a YAML file. I want to just change a single value inside that YAML file. I found yaml-cpp library being used widely for parsing/editing yaml files from c++ code. Is there a way I can update single value and leave the rest of the file untouched?
I have a YAML file like this already. And I just want to update the parameter 'non_ros_map_width'
# Config file
package_name: "auto_mapping_ros"
csv_filepath: "/csv/sequence"
# Non ROS Map Values
non_ros_map_width : 1000
I tried runnning using yaml-cpp and updated it from the cpp code and I got this:
package_name: !<!> auto_mapping_ros
non_ros_map_height: 1355
csv_filepath: !<!> /csv/sequence
The values seem to be intact. I am not sure about the strings. but my comments have disappeared. Is there a way to just update the single value and not touch the rest of the file.
My code snippet:
YAML::Node node, _baseNode = YAML::LoadFile(auto_mapping_yaml_path); // gets the root node
_baseNode["non_ros_map_width"] = 1355; // edit one of the nodes
std::ofstream fout(auto_mapping_yaml_path);
fout << _baseNode; // dump it back into the file