std::fstream config_file("config.yaml", std::ios::in | std::ios::out);
YAML::Node config_node = YAML::Load(config_file);
config_file.close();
// For example parse over the config, confirm it's correct, maybe correct mistakes, update the config to a new version, etc...
std::fstream config_file_write("config.yaml", std::ios::out | std::ios::trunc);
YAML::Emitter emitter;
emitter << config_node;
config_file_write << emitter.c_str();
Now maybe the user has written some comments in the config file to remind themselves why they set an option to that value. If the config is for example loaded through a GUI and modified or the config is loaded by the application and modified any way and then the config is saved again, the user's comments are lost.
Is there any way to preserve the comments when emitting the original parsed object?
For example I have the following code:
Now maybe the user has written some comments in the config file to remind themselves why they set an option to that value. If the config is for example loaded through a GUI and modified or the config is loaded by the application and modified any way and then the config is saved again, the user's comments are lost.
Is there any way to preserve the comments when emitting the original parsed object?