I had something simple like this POD structure...
struct Actor
{
string name;
int hp;
};
Later on, for simplicity sake here, I saved the structure to file using...
ofstream_obj.write((char *)&PC, sizeof(Actor));
Then, I tried reading the file back. It loaded in the data, but upon exit it gave an ugly exception, pointing at xutility at the line of: *_Pnext != 0
inline void _Container_base12::_Orphan_all()
{ // orphan all iterators
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Myproxy != 0)
{ // proxy allocated, drain it
_Lockit _Lock(_LOCK_DEBUG);
for (_Iterator_base12 **_Pnext = &_Myproxy->_Myfirstiter;
*_Pnext != 0; *_Pnext = (*_Pnext)->_Mynextiter)
(*_Pnext)->_Myproxy = 0;
_Myproxy->_Myfirstiter = 0;
}
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
}
After giving up, I changed the std::string to char name[20], tried the whole thing again, and it worked fine. Is there something different about loading back std::string? Is it not calling std::string's copy constructor?