Search code examples
yaml-cpp

YAML ofstream emitter


I find this example:

ofstream ofstr("output.yaml");
YAML::Emitter out(ofstr);
out << some_large_document;

// not necessary anymore:
// ofstr << out.c_str()

But when i try use it, i have:

D:\work\C\map.cpp||In function `int main()':|
D:\work\C\map.cpp|24|error: no matching function for call to `YAML::Emitter::Emitter(std::ofstream&)'|
D:\work\C\yaml-cpp\emitter.h|23|note: candidates are: YAML::Emitter::Emitter(YAML::Emitter&)|
D:\work\C\yaml-cpp\emitter.h|25|note:                 YAML::Emitter::Emitter()|
||=== Build finished: 1 errors, 0 warnings ===|

Solution

  • There's no constructor to YAML::Emitter that takes a stream. (Where did you find that example?)

    Instead, you do need to use the commented out line:

    ofstream ofstr("output.yaml");
    YAML::Emitter out;
    out << some_large_document;
    ofstr << out.c_str(); // is necessary!