## ::iterator it; erase(it); 删除容器里迭代器it当前所指向位置的元素,导致it成为野指针,使得it++操作存在异常
# vector - erase
//迭代器
for(size_t j = 0; j < v_needqids.size(); ++j){
if(find(v_uqids.begin(),v_uqids.end(),v_needqids[j]) == v_uqids.end()){
it = vst.erase(it); //返回指向下一个元素的迭代器
--it;
break;
}
}
//erase之后还可以读取
{
vector<char*> v;
v.clear();
cout << v.size() << endl; //0
char* chs = "abc123";
v.push_back(chs);
cout << v.size() << endl; //1
char* _chs = v[0];
cout << _chs << endl; //abc123
v.erase(v.begin()); //erase之后还可以读取
cout << v.size() << endl; //0
char* _chs2 = v[0];
cout << _chs2 << endl; //abc123
char* chs2 = "def456";
v.push_back(chs2);
cout << v.size() << endl; //1
char* _chs3 = v[0];
cout << _chs3 << endl; //def456
}
# map - erase
for(map<uint32_t, StUserQuest>::iterator it = questData.begin(); it != questData.end(); ++it){
if((long)it->second.m_u32_access_time > now){
map<uint32_t, StUserQuest>::iterator ittmp = it;
it++;
questData.erase(ittmp); //未到开放时间
it--;
}
}