XML-Serialization_Problem with loading...
I have a problem with serialization in XML-format.
The ser.routine saves the data as xml, but when trying to reload, the
execution breaks. When using the text-output saving and loading works
fine...
I hope someone can help me:
Here the code of the functions:
------------------------------------------------
main.cpp:
------------------------------------------------
#include "fixture.h"
#include
I'm suspicious of oa << BOOST_SERIALIZATION_NVP(*fixt); This assigns an XML tag name of <*fixt> which I suspect isn't kosher. You might try: oa << boost::serialization::nvp("fixt_tag", *fixt); See if that helps. BTW, I find things like oa << *x; very odd. Its not clear what the intention is to me. I would have written p.speck@ewersbach.net wrote:
I have a problem with serialization in XML-format.
The ser.routine saves the data as xml, but when trying to reload, the execution breaks. When using the text-output saving and loading works fine...
I hope someone can help me: Here the code of the functions: ------------------------------------------------ main.cpp: ------------------------------------------------
#include "fixture.h" #include
#include #include <iostream> #include <fstream> #include <string> #include <sstream> void save(CFixture* fixt, const char* filename) { ofstream ofs(filename); assert(ofs.good()); boost::archive::xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(*fixt); ofs.close(); }
void load(CFixture* fixt, const char* filename) { ifstream ifs(filename); assert(ifs.good()); cout << filename << endl; boost::archive::xml_iarchive ia(ifs); cout << "Archive" << endl; ia >> BOOST_SERIALIZATION_NVP(*fixt); cout << "loaded" << endl; ifs.close(); }
I would have written: void save(const CFixture & fixt, const char* filename) { ... oa << BOOST_SERIALIZATION_NVP(fixt); ... } void load(CFixture & fixt, const char* filename) { ... ia >> BOOST_SERIALIZATION_NVP(fixt); ... } Robert Ramey
participants (2)
-
p.speck@ewersbach.net
-
Robert Ramey