std::map的删除

 1 void eraseMap()
 2 {
 3 int n = sizeof(MmMethod);
 4 std::map<CString, int>mapDemo;
 5 for(int i = 0; i < 5; i++)
 6 {
 7 CString strKey;
 8 strKey.Format(_T("key:%d"), i);
 9 mapDemo.insert(std::make_pair(strKey, i));
10 }
11 
12 for(auto it = mapDemo.begin(); it != mapDemo.end(); /*it++*/)
13 {
14 int n = it->second;
15 if(it->second == 2)
16 {
17 mapDemo.erase(it++);//或者it = mapDemo.erase(it);
18 }
19 else
20 {
21 it++;
22 }
23 }
24 }
原文地址:https://www.cnblogs.com/lpxblog/p/5886318.html