map 函数

#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;
}
发布了106 篇原创文章 · 获赞 25 · 访问量 7223

猜你喜欢

转载自blog.csdn.net/weixin_45653525/article/details/104198083