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;
}