很好的例子,供大家参考。
#include <map>
#include <iostream>
#include <stdio.h>
#include <string>
#include <map>
using namespace std;
int main()
{
map<int,int> _map;
for (int i = 0; i < 10; i++)
{
_map.insert(make_pair(i,i+1));
}
for (map<int,int>::iterator iter = _map.begin(); iter != _map.end();)
{
if (iter->first % 3 == 0)
{
_map.erase(iter++);
}
else
{
iter++;
}
}
for (map<int,int>::iterator iter = _map.begin(); iter != _map.end(); ++iter)
{
cout<<iter->first<<endl;
}
return 0;
}