Closed GoogleCodeExporter closed 9 years ago
In your code:
emitter << YAML::BeginMap;
emitter << YAML::Key << "Name1" << YAML::Value << "Val1";
emitter << YAML::BeginMap; // <--- this line
emitter << YAML::Key << "Name2" << YAML::Value << "Val2";
emitter << YAML::Key << "Name3" << YAML::Value << "Val3";
emitter << YAML::EndMap;
emitter << YAML::Key << "Name5" << YAML::Value << "Val5";
emitter << YAML::EndMap;
The indicated line is in the "key" position of a map (the first entry in a
key/value pair). yaml-cpp doesn't actually need the YAML::Key / YAML::Value
entries (although this example makes me think that maybe it should produce an
error if you use them incorrectly).
In any case, this throws the key/value pairs off by one. The second key in your
map is the nested map, and its associated value is "Name5" (as printed). The
third key is "Val5", and there's no associated value. Presumably, you want:
emitter << YAML::BeginMap;
emitter << YAML::Key << "Name1" << YAML::Value << "Val1";
emitter << YAML::Key << "Maps";
emitter << YAML::Value << YAML::BeginMap;
emitter << YAML::Key << "Name2" << YAML::Value << "Val2";
emitter << YAML::Key << "Name3" << YAML::Value << "Val3";
emitter << YAML::EndMap;
emitter << YAML::Key << "Name5" << YAML::Value << "Val5";
emitter << YAML::EndMap;
This should produce the output you list at the bottom.
Original comment by jbe...@gmail.com
on 1 Jun 2013 at 8:14
Original issue reported on code.google.com by
DenisKra...@gmail.com
on 17 May 2013 at 1:34