通过iterator来遍历vector成员用erase删除结点会出现错误,
如下程序:
#include<iostream> #include<vector> #include<algorithm> using namespace std; struct cuttime{ int index; long begin; long end; }; vector<cuttime> vec_cutdata; vector<cuttime>::iterator cutdata_iter; int main() { cuttime cut1,cut2,cut3,cut4; cut1.index=1; cut1.begin=5; cut1.end=10; cut2.index=2; cut2.begin=6; cut2.end=12; cut3.index=3; cut3.begin=7; cut3.end=14; cut4.index=4; cut4.begin=8; cut4.end=15; vec_cutdata.push_back(cut1); vec_cutdata.push_back(cut2); vec_cutdata.push_back(cut3); vec_cutdata.push_back(cut4); vector<cuttime>::iterator it; for(it=vec_cutdata.begin();it!