我是靠谱客的博主 忧郁钻石,这篇文章主要介绍unordered_set/unordered_map 增删查操作unordered_setunordered_map,现在分享给大家,希望可以做个参考。

unordered_set

//引入头文件
#include<unordered_set>

//创建
unordered_set<int> num;

//添加
num.insert(3);

//删除
num.erase(3);

//查找
if(num.find(3)==num.end()) cout<<"3 is not found!";

unordered_map

//引入头文件
#include<unordered_map>

//创建
unordered_map<string,int> str;

//添加(key,value)
str.insert("C++",10);
str.insert("Java",100);

//删除
str.erase("C++");

//查找
if(str.find("C++")==str.end()) cout<<"C++ is not found!";

另外C++ 对unordered_map 赋予了数组相关的操作,可以类似于数组一样的方法对unordered_map 进行添加,修改等操作。
详见:
C++ 中使用hashmap哈希表的常用操作

最后

以上就是忧郁钻石最近收集整理的关于unordered_set/unordered_map 增删查操作unordered_setunordered_map的全部内容,更多相关unordered_set/unordered_map内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(94)

评论列表共有 0 条评论

立即
投稿
返回
顶部