By running this code:
#include <yaml-cpp/yaml.h>
#include <iostream>
#include <fstream>
int main() {
{
std::ofstream f("hola.yaml");
YAML::Emitter emitter(f);
emitter << YAML::Literal << "Hello\nworld" << YAML::Comment("Un comentario");
}
{
std::ifstream f("hola.yaml");
YAML::Node node = YAML::Load(f);
std::cout << node.as<std::string>() << std::endl;
}
return 0;
}
The first part generates the following content:
|
Hello
world # A comment
When the second part reads it back, the comment is read as part of the literal. One of them, reading or writing is wrong. Specs says that no comments can be placed inside an scalar, since a literal is an scalar and it terminates with the indentation back, it sounds like the reading is right and the writing is wrong.
When a scalar is inserted in literal mode comments inserted next should be at the next line. and outside of the indentation. Like this:
|
Hello
world
# A comment
By running this code:
The first part generates the following content:
When the second part reads it back, the comment is read as part of the literal. One of them, reading or writing is wrong. Specs says that no comments can be placed inside an scalar, since a literal is an scalar and it terminates with the indentation back, it sounds like the reading is right and the writing is wrong.
When a scalar is inserted in literal mode comments inserted next should be at the next line. and outside of the indentation. Like this: