Hello, Benjamin.Sternlieb@ubs.com 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