我有一个像这样的POD结构简单的东西...
struct Actor
{
string name;
int hp;
};
稍后,为简便起见,我使用...将结构保存到文件中。
ofstream_obj.write((char *)&PC, sizeof(Actor));
然后,我尝试将文件读回。 它加载了数据,但是在退出时却给出了一个丑陋的异常,在以下行中指向xutility:* _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 */
}
放弃后,我将std :: string更改为char name [20],再次尝试了整个操作,并且工作正常。 加载std :: string有什么不同吗? 它不是在调用std :: string的副本构造函数吗?