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内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复