tags:

views:

34

answers:

1

I just started playing around with yaml-cpp, I managed to build it properly and run some of the examples from the yaml-cpp wiki but I can't find a way to save my emitter to a file.

Is this not possible? I mean the PyYAML library has a 'dump' function for this. Is there no such functionality in yaml-cpp? Is there some workaround to converting a yaml emitter to a stl stream and then dumping this to a yaml file?

Please let me know

Thanks, Adam

A: 

The function Emitter::c_str() returns a NULL-terminated C-style string (which you do not have to release), which you can then write to a file. For example:

YAML::Emitter emitter;
emitter << "Hello world!";

std::ofstream fout("file.txt");
fout << emitter.c_str();

There is also Emitter::size(), which returns the number of bytes in that string, in case you want to do something more advanced and don't want to walk the string to find its length.

If your question is about a shortcut to the above, then there is none; but you could write one :)

(In a future update, I'm leaning towards putting some shortcuts in like this, but it's (unfortunately) a low priority.)

Jesse Beder
Ah that seems to do the trick...Thanks a lot Jesse. Keep up the good work!!!
somada141