
CurieCat wrote:
Hi, I tried to save a tree structure out to an archive and then read it back. If I use a text archiver, everything works fine; If I use a binary archiver, an exception of "stream error" is thrown. I managed to shorten my code as
following. Can anyone give some advice? I'm using vs2008 and boost
1.42.0. Thanks.
[snip]
const Node* rootnode = root ;
Node* newroot = NULL; std::ofstream ofs("filename"); {
boost::archive::binary_oarchive oa(ofs); oa << rootnode; } ofs.close();
std::ifstream ifs("filename"); { boost::archive::binary_iarchive ia(ifs);
ia >> newroot; } ifs.close();
return 0; }
The first obvious thing I can notice with the code above is that it's not opening the files in binary mode. Try std::ofstream ofs("filename", std::ios_base::binary); and std::ifstream ifs("filename", std::ios_base::binary); HTH, Gevorg