I am using boost serialization for serializing objects. In Linux all goes fine, but in Windows I am having problems deserializing data:
std::ifstream ifs(dataFilename.str().c_str(), std::ios开发者_如何学C::in | std::ios::binary);
{
boost::archive::binary_iarchive persistenceFile(ifs);
persistenceFile >> activeMessageAux;
persistenceFile >> activeMessageAux2;
}
And always fail on the second deserializing to activeMessageAux2, receiving a boost::archive::archive_exception
input stream error. I can see that in the file I have all entrys that I suppose to have, so, I dont know why I'm having this exception. What could I do? Any idea?
If the entirety of the serialized data has been deserialized into activeMessageAux
, why can't you just use normal assignment to populate activeMessageAux2
?
std::ifstream ifs(dataFilename.str().c_str(), std::ios::in | std::ios::binary);
{
boost::archive::binary_iarchive persistenceFile(ifs);
persistenceFile >> activeMessageAux;
}
activeMessageAux2 = activeMessageAux;
The flag std::ios::binary
is required only in Windows, where the default mode (ascii) would translate \n\r to \n (and vice versa), thus corrupting any data that is not textual.
Have you set it also in the export?
Finally I found a solution. Read an object, save the position with tellg and after that I can read the next object. :-D
精彩评论