stl-map stl-pair
2014-02-22 18:58
316 查看
pair
模板类,用于创建 键/值 关联对。//pair #include #include #include #include using namespace std; int main(int argc, char *argv[]) { pair CppPrimer("Stanlly B.Lippman",120); cout< struct pair { _T1 first; _T2 second; } #endif
map
映射。详尽参考见;http://www.cplusplus.com/reference/map/map/注意map[key]=value这种简便形式。
#include #include using namespace std; int main() { map m_map; string str1="hi",str2; if(m_map.find(str1)==m_map.end()) cout<<"not found"; m_map[str1]=3; cout<
注意count() 与 find()函数
#include #include #include using namespace std; int main(){ map m; m[1]='a',m[2]='b'; for(auto x:m) cout<0) { cout<<"m contains key:2\n"; map::iterator it= m.find(2); cout<<"the key:2 is corresponding to value:"<second; } return 0; } /* 1a 2b ----------- m does NOT contain key:3 m contains key:2 the key:2 is corresponding to value:b Process returned 0 (0x0) execution time : 0.158 s Press any key to continue. */
hash_map
哈希映射hash_map的用法和map是一样的,提供了 insert,size等操作,并且里面的元素也是以pair类型来存贮的。虽然对外部提供的函数和数据类型是一致的,但是其底层实现是完全不同的,map底层的数据结构是rb_tree而hash_map却是哈希表。
#include #include #include using namespace std; int main(){ hash_mapx; x.insert(pair(3,4)); x.insert(hash_map::value_type(1,2)); cout<
相关文章推荐
- stl-map-pair
- STL之关联容器(pair、map、set的使用)
- Codeforces Round #377 (Div. 2) E. Sockets(map,pair,STL)
- STL的pair学习, map学习
- 巧妙地利用STL map set pair 贪心+排序 Codeforces Round #331 (Div. 2)C. Wilbur and Points
- STL中map, list, and pair的学习笔记
- c++ STL 之map 和 pair
- STL笔记:map and pair
- POJ 3297 Open Source STL(map+set+pair)
- STL中的模板类pair 和map http://blog.csdn.net/calvin_zcx/article/details/6072286
- stl之pair,map,vector区别
- c++之STL之pair,map
- STL中的模板类pair 和map
- stl : map 插入相同key组成的make_pair, 结果是插入不进去, 不是覆盖
- STL之关联容器(pair、map、set的使用)
- STL中的模板类pair 和map
- STL 之 pair 和map
- C++学习STL之关联容器 --- pair、map、set
- HDU 4287 Intelligent IME(string,map,stl,make_pair)
- STL----map