#include <iostream>
#include <map>
using namespace std;
int main()
{
//——————————————————————————————————这个默认删除
map<string, int> mp = {{"Tom", 0}, {"Tom", 1}, {"Bob", 100}, {"Alan", 100}};
//插入
mp.insert(make_pair("Zhang", 100));
//删除 先用迭代器找到
// map<string, int>::iterator it;
auto t = mp.begin();
t = mp.find("Tom");
mp.erase(t);
//出现次数
cout << mp.count("Tom");
for (auto i = mp.begin(); i != mp.end(); ++i)
{
cout << i->first << ' ' << i->second << endl;
}
return 0;
}
来源:CSDN
作者:陌陌623
链接:https://blog.csdn.net/weixin_45653525/article/details/104198083