0
点赞
收藏
分享

微信扫一扫

map的insert会自动忽略重复key,而不是替换

木樨点点 2023-04-17 阅读 59


uint32_t nID = 0;
    map<string, uint32_t> str2IntMap;
    for(int i = 0; i < 10; ++i)
    {
        str2IntMap.insert(make_pair("a", nID));
        ++nID;
    }
    for(map<string, uint32_t>::iterator it = str2IntMap.begin(); it != str2IntMap.end(); ++it)
    {
        printf("%d=%s\n", it->second, it->first.c_str());
    }


上面会输出:0=a


key为a的pair插入第一组 a,0后,

再插入 a,1,自动忽略。


举报

相关推荐

0 条评论