字典map与pair一对
字典map是键和键值一起出现的
使用字典 map 需要头文件定义#include <map> 
map<数据类型1,数据类型2> mp
map<int,string> mp;
对模板进行类型定义后使用会很方便1
2typedef std::map<int , std::string> MAP_INI_STRING;
MAP_INI_STRING person;
map添加数据
- 数组方式插入 
 mp[1] = “ketti”;
- insert 插入 pair数据 
| 1 | std::map < int , std::string > mpPerson; | 
- insert 插入 value_type 数据
 mpPerson.insert(std::map < int, std::string > ::value_type (2, “Tom”));
pair
pair是一种模版类型。每个pair 可以存储两个值。这两种值的类型没有限制,也可以将自己写的类放进去
pair<int,int> p; 
p->first = 1;p->second = 1;
| 1 | pair<int ,int >p (5,6); | 
map基本操作
map 的基本操作函数:
C++ Maps 是一种关联式容器,包含“关键字/值”对
begin()                  返回指向 map 头部的迭代器
clear()                 删除所有元素
count()                  返回指定元素出现的次数
empty()                 如果 map 为空则返回 true
end()                     返回指向 map 末尾的迭代器 `mp.find(key)!=mp.end()` 如果相等代表没找到
equal_range()        返回特殊条目的迭代器对
erase()                   删除一个元素
find()                     查找一个元素  
get_allocator()      返回map的配置器
insert()                  插入元素 mp.insert({ 1, "张三" });
key_comp()          返回比较元素key的函数
lower_bound()     返回键值>=给定元素的第一个位置
max_size()            返回可以容纳的最大元素个数
rbegin()                返回一个指向map尾部的逆向迭代器
rend()                   返回一个指向map头部的逆向迭代器
size()                    返回map中元素的个数
swap()                 交换两个map
upper_bound()    返回键值>给定元素的第一个位置
value_comp()       返回比较元素value的函数
map的遍历
可以用迭代器,或者数组样式1
2
3map<int, string>::iterator it = mp.begin();
for (it = mp.begin(); it != mp.end(); it++)
		cout << it->first << " " << it->second << endl;
创建一个map 查找迭代器map<string,int>::iterator itr=m.find(val);
 //Gives the iterator to the element val if it is found otherwise returns m.end() .
