map
来源:互联网 发布:windows介质创建工具 编辑:程序博客网 时间:2024/05/15 16:42
Before talking about map, we need to know pair. The class pair treats two values as a single unit. This class is used in several places within the C++ standard library. In particular, the container classes map, multimap, unordered_map, and unordered_multimap use pairs to manage their elements, which are key/value pairs. The structure pair is defined in <utility> and provides the operations listed below. In principle, you can create, copy/assign/swap, and compare a pair<>. In addition, there are type definitions for first_type and second_type, representing the types of the first and second values.
To process the values of the pair direct access to the corresponding members is provided. In fact, the type is declared as struct instead of class so that all members are public:
template <typename T1, typename T2>struct pair { // member T1 first; T2 second; ...};
Some basic operations for map in stl.
#include<iostream>#include<map>using namespace std;int main(){ map<int, string> mymap; pair<int, string> s1(1, "Tim"); pair<int, string> s2(2, "Sam"); pair<int, string> s3(6, "David"); pair<int, string> s4(5, "James"); pair<int, string> s5(1, "Tim"); mymap.insert(s1); mymap.insert(s2); mymap.insert(s3); mymap.insert(s4); mymap.insert(s5); map<int, string>::iterator itr = mymap.begin(); while(itr!=mymap.end()){ cout << (*itr).first << "\t" << (*itr).second << endl; itr++; } return 0;}
One more example.
- map
- MAP
- map
- MAP
- map
- map
- map
- Map
- Map
- Map
- map
- map
- Map
- .map
- map
- MAP
- map
- Map
- 一个cocos2d学习博客
- ebuy遇到的问题以及解决方法
- 数据挖掘2-数据描述
- Java基础视频教程第08天_面向对象之多态
- 商品分类插入商品父类触发器
- map
- 《Python核心编程》数字类型
- android Intent机制详解
- Lucene关系数据库的使用
- Leetcode: Dungeon Game
- MATLAB日记01
- 验证码生成和验证servlet
- [NOI2011]智能车比赛(计算几何+动态规划)
- html5学习渐阶笔记---样式,链接,表格