-
Notifications
You must be signed in to change notification settings - Fork 0
/
C++STL_map
40 lines (35 loc) · 1.24 KB
/
C++STL_map
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
map:https://www.cnblogs.com/leaves1024/p/10565834.html
map是一种关联容器,它按照特定顺序存储由键值Key和映射值Value组合而成的元素.
在map中,键值key通常用于排序和唯一标识元素,而映射值Value存储与此键值Key相关联的内容,键Key和映射值Value的类型可能不同,并在成员类型value_type中组合在
一起,value_type是一个组合了两种类型的pair类型:typedef pair<const Key,T> value_type.
https://www.jianshu.com/p/4ddc02a22c9b
关于关于关联容器举例子:键值 小明 映射值 :电话号码 qq wechat
map数据的遍历:
map反向迭代器的使用实战
int main()
{
map<int, string> mapStudent;
mapStudent[1] = "student_one";
mapStudent[2] = "student_two";
mapStudent[3] = "student_three";
map<int,string>::reverse_iterator iter;
for(iter = mapStudent.rbegin();iter != mapStudent.rend(); iter++)
{
cout<<iter->first<<" "<<iter->second<<endl;
}
return 0;
}
用数组方式遍历map
int main()
{
map<int,string> mapStudent;
mapStudent[1] = "student_one";
mapStudent[2] = "student_two";
mapStudent[3] = "student_three";
int iSize = mapStudent.size();
for(int i = 1; i <= iSize; i++)
{
cout <<i<<" "<<mapStudent[i]<<endl;
}
return 0;
}