0

The following code does not write to file.

#include <cereal/types/vector.hpp>
#include <cereal/archives/xml.hpp>
{
    vector<int> v = { 1,2,3 };
    stringstream s;
    s << "cereal_test.xml";
    cereal::XMLOutputArchive  oarchive(s);
    oarchive(v); 
}

It compiles and runs apparently correctly.

If we cout << s << endl; out of scope we see in the console:

cereal_test.xml
<?xml version="1.0" encoding="utf-8"?>
<cereal>
        <value0 size="dynamic">
                <value0>1</value0>
                <value1>2</value1>
                <value2>3</value2>
        </value0>
</cereal>

What's missing?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
WurmD
  • 1,231
  • 5
  • 21
  • 42
  • 1
    You say that the code doesn't write to a file, but it doesn't actually *write to a file*. All it does is the serialization to a string stream, nowhere do you write the serialized data to a file. – Some programmer dude Mar 06 '19 at 15:05
  • That is a fair point. However, this is pretty much copy paste from cereal's documentation https://uscilab.github.io/cereal/quickstart.html ; when we produce a working code I'll pull request that change to their documentation – WurmD Mar 06 '19 at 15:26

1 Answers1

0

A mistaken copy-paste from cereal's tuturial:

It should be ofstream instead of stringstream

{
    vector<int> v = { 1,2,3 };

    std::ofstream outFile("cereal_test.xml");
    {
        cereal::XMLOutputArchive  oarchive(outFile);
        oarchive(v);
    }
}
WurmD
  • 1,231
  • 5
  • 21
  • 42