循环奇怪中断(map)
目的:全部删除'f'问题:循环中断,无法全部删除
#include<iostream>
#include<map>
using namespace std;
int main()
{
map<int, char> m1;
m1[10010] = 'm';
m1[10011] = 'f';
m1[10012] = 'f';
m1[10013] = 'm';
m1[10014] = 'f';
m1[10015] = 'm';
//删除'f'
for(int i = 10010; i < m1.size()+10010; i++)
{
cout << i << " ";
//到第3次就中断了
if(m1[i] == 'f')
{
m1.erase(i);
}
}
//输出结果
for(map<int, char>::iterator it = m1.begin(); it != m1.end(); it++)
{
cout << it->second << " ";
}
cout << endl;
}