Microsoft Visual Studio C Runtime Library has detected a fatal error in STLtest.exe.
Press Break to debug the program or Continue to terminate the program.
该问题主要是由于对结构体变量使用了memset函数,如果结构体中有vector这样的类型,使用memset会导致结构体中的某些信息丢失,从而在使用push_back函数插入数据时产生异常中断。希望我的遭遇对大家有帮助。
#include "stdafx.h"
#include <vector>
#include <iostream>
using namespace std;
typedef struct _structBB
{
int i;
vector<int> vBBs;
}BB;
int _tmain(int argc, _TCHAR* argv[])
{
BB bb;
memset(&bb,0,sizeof(BB));
bb.vBBs.push_back(1);
return 0;
}