|
Boost Users : |
From: Martin Ecker (martin.ecker_at_[hidden])
Date: 2005-06-21 15:35:30
Hello,
Benjamin.Sternlieb_at_[hidden] wrote:
> I was trying out boost serialization and ran into a snag. If I serialize the same object onto two xml_oarchives, one constructed with a ostringstream and one constructed with an ofstream, I get differing results - the file based xml is well formed, but the string based xml is missing its final closing tag.
>
> Here is the generating code snippet:
>
> // now serialize
> ostringstream os;
> boost::archive::xml_oarchive ar(os);
> ofstream ofs("/home/sternlbe/boo.xml");
> boost::archive::xml_oarchive ar2(ofs);
> Portfolio& port = *p;
> ar << BOOST_SERIALIZATION_NVP(port);
> ar2 << BOOST_SERIALIZATION_NVP(port);
> string s = os.str();
> LOG_DEBUG(logger) << "Xml string: \n" << s;
You should always make sure the archive object has been closed and destroyed
before accessing any results. Try this and it should work:
ostringstream os;
ofstream ofs("/home/sternlbe/boo.xml");
{
boost::archive::xml_oarchive ar(os);
boost::archive::xml_oarchive ar2(ofs);
Portfolio& port = *p;
ar << BOOST_SERIALIZATION_NVP(port);
ar2 << BOOST_SERIALIZATION_NVP(port);
}
string s = os.str();
LOG_DEBUG(logger) << "Xml string: \n" << s;
Best Regards,
Martin
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net