声明:
map<type,type> m; //第一个type为 key, 第二个即为 key对应的值,
type可以是任意类型; //map与set一样,不含重复元素;
map<int,string> mapstudent;
插入:
3种方式,insert插入 pair、 insert插入value_type、 数组方式
1: mapstudent.insert(pair<int,string>(1,"student_one"));
2: mapstudent.insert(map<int,string>::value_type(2,"student_two"));
3: map[3]="student_three";
遍历: 迭代器遍历即可
map<int,string>::iteator it;
for(it=mapstudent.begin();it!=mapstudent.end();it++)
cout<<(*it).first<<" "<<(*it).second;
count()函数: 判断 key值是否存在,存在返回1,否则返回0;
其他函数:
大小: .size()
清空: .clear()
删除: .erase()
判空: .empty()
map<type,type> m; //第一个type为 key, 第二个即为 key对应的值,
type可以是任意类型; //map与set一样,不含重复元素;
插入:
3种方式,insert插入 pair、 insert插入value_type、 数组方式
1: mapstudent.insert(pair<int,string>(1,"student_one"));
2: mapstudent.insert(map<int,string>::value_type(2,"student_two"));
3: map[3]="student_three";
遍历: 迭代器遍历即可
map<int,string>::iteator it;
for(it=mapstudent.begin();it!=mapstudent.end();it++)
cout<<(*it).first<<" "<<(*it).second;
count()函数: 判断 key值是否存在,存在返回1,否则返回0;
其他函数:
大小: .size()
清空: .clear()
删除: .erase()
判空: .empty()