I want to emit a seqence of mappings using the yaml-cpp library in the following format:
-
name: <some_name>
value: <some_value>
I'm using this code:
Emitter out;
out << YAML::BeginSeq;
for (unsigned int i = 0; i < prof_info_.numOfSettings; ++i)
{
str = NvUS_to_string(stgs[i].settingName);
if (str != "")
{
out << YAML::BeginMap;
out << YAML::Key << "name";
out << YAML::Value << str;
string d_str = get_value_name_from_value_id(stgs[i].settingId, (unsigned int)stgs[i].u32CurrentValue);
out << YAML::Key << "value";
out << YAML::Value << d_str;
out << YAML::EndMap;
}
}
out << YAML::EndSeq;
f_out << out.c_str();
and I'm getting:
- name: <some_name>
value: <some_value>
I tried adding
out << YAML::NewLine;
at the beginning of the map, but it gives the wrong result. How can I get the output I want?
Put YAML::Newline
just after YAML::BeginMap
to get the newline after the -
but before the first entry of the map:
out << YAML::BeginMap;
out << YAML::Newline;
out << YAML::Key << "name";
out << YAML::Value << str;
out << YAML::Key << "value";
out << YAML::Value << d_str;
out << YAML::EndMap;