64,648
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <map>
using namespace std;
int main(int argc, char** argv)
{
map<int32_t, string> testMap;
testMap.insert(make_pair(1, "one"));
testMap.insert(make_pair(2, "two"));
map<int32_t, string>::iterator iter = testMap.begin();
for (; iter != testMap.end(); iter++) {
cout << "iter = (" << iter->first << " --> " << iter->second << ")." << endl;
}
map<int32_t, string>::iterator it = testMap.find(1);
cout << "it = (" << it->first << " --> " << it->second << ")." << endl;
map<int32_t, string>::iterator jt = testMap.find(2);
cout << "jt = (" << jt->first << " --> " << jt->second << ")." << endl;
/*testMap.erase(jt);
cout << "it = (" << it->first << " --> " << it->second << ")." << endl;*/
testMap.erase(it);
cout << "jt = (" << jt->first << " --> " << jt->second << ")." << endl;
testMap.insert(make_pair(3, "three"));
testMap.insert(make_pair(4, "four"));
testMap.insert(make_pair(5, "five"));
iter = testMap.begin();
for (; iter != testMap.end(); iter++) {
cout << "iter = (" << iter->first << " --> " << iter->second << ")." << endl;
}
it = testMap.find(4);
cout << "it = (" << it->first << " --> " << it->second << ")." << endl;
testMap.erase(it);
cout << "jt = (" << jt->first << " --> " << jt->second << ")." << endl;
return 0;
}