map<string, int> m; <key,value> m["one"] = 1; map<string, int>::iterator p = m.begin(); p->first; // 这个是 string 值是 "one" p->second; //这个是 int 值是 1 */unordered_set/* 函数声明 功能介绍 begin 返回unordered_set第一个元素的迭代器 end 返回unordered_set最后一个元素...
#include <iostream>#include <unordered_set>int main() {// 创建一个unordered_setstd::unordered_set<int> mySet;// 向unordered_set中插入元素mySet.insert(5);mySet.insert(2);mySet.insert(8);// 查找元素if (mySet.find(2) != mySet.end()) {std::cout << "元素 2 存在于unordered_set...
方法1:使用auto遍历 unordered_map<int,int> map;for(autov : map) {cout << v.first << v.second() << endl;} 方法2:使用迭代器遍历 unordered_map<int,int> map;for(unordered_map<int,int>::iterator = map.begin(); it != map.end(); it++) {cout << it->first << it->second() ...
set<int,greater<int>>GREATER_SET;//自动排序去重按从大到小排,必须加上functional头文件 set<int>SET;//自动排序从小到大 multiset<int>MULTI_SET;//自动排序不去重不加比较类(greater<int>)默认是从小到大排序 unordered_set<int>UNORDERED_SET;//不自动排序但去重 unordered_multiset<int>UNORDERED_MULTISET;...
unordered_set常用接口 迭代器相关 unordered_set没有反向迭代器。 示例 void unordered_set_test2(){unordered_set<int> us;us.insert(1);us.insert(1); // 去重us.insert(2);us.insert(5);us.insert(4);us.insert(3);us.insert(6);for (auto e : us) // 使用范围for遍历{cout << e << " ...
int main () { std::unordered_set<std::string> first; // empty std::unordered_set<std::string> second ( {"red","green","blue"} ); // init list std::unordered_set<std::string> third ( {"orange","pink","yellow"} ); // init list ...
unordered_set<pair<int, int>, myHash> S; int x, y; while (cin >> x >> y) S.insert(make_pair(x, y)); for (auto it = S.begin(); it != S.end(); ++it) cout << it->first << " " << it->second << endl;
map,unordered_map,set,unordered_set map 底层是用红黑树实现的(所以默认为时有序的),map是按value排序的。map的元素是pair,map的first用作索引,second是索引的值,提供一对一的hash。操作insert,可以通过插入pair实现插入。 insert插入 map<int, string> mapStudent;...
The second constructor specifies an empty controlled sequence. The third constructor specifies a copy of the sequence by moving Right The fourth through eighth constructors use an initializer_list to specify the elements to copy. The ninth constructor inserts the sequence of element values [first, ...
compile with: /EHsc #include <unordered_set> #include <iostream> typedef std::unordered_set<char> Myset; int main() { Myset c1; c1.insert('a'); c1.insert('b'); c1.insert('c'); // display contents "[c] [b] [a] " for (Myset::const_iterator it = c1.begin(); it !