c++
STL 中map 插入和删除的一些小细节
#include<iostream>
using namespace std;
#include<map>
void printmap(map<int, int>&ma)
{
for (map<int, int>::iterator it = ma.begin(); it != ma.end(); it++)
{
cout << " first = " << it->first << " second = " << it->second << endl;
}
}
void test01()
{
map<int, int> ma;
ma.insert(pair<int, int>(2, 54));
ma.insert(make_pair(3, 78));
ma.insert(map<int, int>::value_type(6, 80));
ma[5] = 90;
ma[5] = 80;
printmap(ma);
cout << " _______________________" << endl;
ma.erase(ma.begin());
printmap(ma);
cout << " _______________________" << endl;
ma.erase(++ma.begin(), ma.end());
printmap(ma);
cout << " _______________________" << endl;
ma.clear();
printmap(ma);
cout << " _______________________" << endl;
}
int main()
{
test01();
system("pause");
return 0;
}