kastnermario / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Emitter assertion on back to back streaming of standard containers #93

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
Build and run the following test program:
#include <yaml-cpp/yaml.h>

#include <map>
#include <string>
#include <iostream>

int main()
{
        std::map<std::string, double> aMap;

        aMap["hi"] = 1.0;
        aMap["there"] = 2.0;
        aMap["hello"] = 3.3;

        YAML::Emitter yaml;
        yaml << aMap;

        std::vector<std::string> names;
        names.push_back("Alex");
        names.push_back("Bill");
        names.push_back("Carl");
        yaml << names;

        std::cout << yaml.c_str() << std::endl;
}

What is the expected output? What do you see instead?
I expect to see:

---
hello: 3.3
hi: 1
there: 2
- Alex
- Bill
- Carl

Instead I see this:
yaml-test: /home/ken/code/yaml-cpp-0.2.5/src/emitter.cpp:238: bool 
YAML::Emitter::GotoNextPreAtomicState(): Assertion `false' failed.
make: *** [test] Aborted (core dumped)

What version of the product are you using? On what operating system?
yaml-cpp-0.2.5 on Ubuntu Linux 10.04 LTS recently updated.

Original issue reported on code.google.com by kgsm...@gmail.com on 1 Feb 2011 at 1:08

GoogleCodeExporter commented 8 years ago
What you expected to see isn't valid YAML: you can't simply "concatenate" two 
YAML types - at its root, a document must be either a map, sequence, or scalar.

Currently, yaml-cpp doesn't support emitting multiple documents (it probably 
will, eventually). For now, just use two emitters for separate documents, or 
wrap the two nodes in a sequence as follows:

YAML::Emitter emitter;
emitter << YAML::BeginSeq;
emitter << aMap;
emitter << aSeq;
emitter << YAML::EndSeq;

Original comment by jbe...@gmail.com on 1 Feb 2011 at 1:20