unordered_map键值重复处理

#include<iostream>

#include<unordered_map>

using namespace std;

int main()

{

    unordered_map<int,int> maptest;

    maptest[1] = 2;

    cout << maptest[1]<< endl;

    maptest[1] = 3;

    cout << maptest[1]<< endl;

    maptest.insert(pair<int, int>(1,4));

    cout << maptest[1]<< endl;

    return 0;

}

输出2 3 3

1、头文件

2、中括号覆盖重复值,所以输出3

3、insert函数是直接扔掉重复插入值,所以输出依旧是3

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
小耳朵嚒的头像 - 鹿快
评论 抢沙发

请登录后发表评论

    暂无评论内容