vector :
iter = container.erase(iter); //erase的返回值是删除元素下一个元素的迭代器
vector<int>::iterator it = a.begin();
for(;it !=a.end();)
{
printf("%d\n",*it);
it = a.erase(it);
}
map:
dataMap.erase(iter++)
注:map erase 没有返回下一个迭代器的方法
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
using namespace std; int main(int argc, char *argv[])
{
vector<int>a;
a.push_back();
a.push_back();
a.push_back();
a.push_back();
vector<int>::iterator it = a.begin();
for(;it !=a.end();)
{
printf("%d\n",*it);
it=a.erase(it);
}
map<int,int>b;
b[]=;
b[]=;
b[]=;
b[]=;
map<int,int>::iterator it1 = b.begin();
for(;it1!=b.end();)
{
printf("%d\n",it1->first);
b.erase(it1++);
} }