#include <iostream>
#include <map>
#include <string>
using namespace std;
template<class t1, class t2>
void outMap(map<t1, t2> &m)
{
typename map<t1, t2>::iterator it;
for (it = m.begin(); it != m.end(); it++)
{
cout << it->first << ","
<< it->second << endl;
}
}
void main()
{
//key , value
map<int, string> myMap;
myMap.insert(make_pair(2, "li"));
myMap.insert(make_pair(1, "zhang"));
myMap.insert(make_pair(2, "li2"));
myMap[3] = "wang";
myMap[4] = "zhao";
//myMap.erase(maMap.begin()+n); //+n error;
//myMap.erase(maMap.begin()+=1); //+= error;
//myMap.erase(++maMap.begin()); //ok
myMap.erase(2);
myMap.erase(myMap.find(3));
outMap(myMap);
}
map
最新推荐文章于 2020-12-30 17:51:12 发布