0

I am trying to get cereal-serialization to work. But somehow it does not work with the XML-Archive in combination with a stringstream.

Here is my example:

std::stringstream ss;

cereal::XMLOutputArchive oarchive(ss);
oarchive(cereal::make_nvp("data", mydata));

ss.str(); //empty

The wierd thing is, that the JSON-Archive is working totally fine, and if a put the std::cout into the XML-Archive, it prints out my serialization. Only the stringstream stays empty.

I tried to find a solution in the documentation but did not find anything about it. Did someone else have a similar problem?

Thanks in advance!

  • 2
    From the [documentation](https://uscilab.github.io/cereal/quickstart.html#serialize-your-data): `"Archives are designed to be used in an RAII manner and are guaranteed to flush their contents only on destruction ..."`. So try scoping `oarchive` such that its destructor is invoked *before* the `ss.str()` call. – G.M. Dec 26 '22 at 12:49
  • Well, next time, I'll put on my glasses. That worked! Thank you! – Philip Schulz Dec 26 '22 at 15:54

0 Answers0