映射和多重映射基于某一类型Key的键集的存在,提供对T类型的数据进行快速和高效的检索。
对map而言,键只是指存储在容器中的某一成员。
Map不支持副本键,multimap支持副本键。
Map和multimap对象包涵了键和各个键有关的值,键和值的数据类型是不相同的,这与set不同。
set中的key和value是Key类型的,而map中的key和value是一个pair结构中的两个分量。
Map<int, string> mapStudent;
mapStudent.insert(pair<int, string>(1, "student_one")); //插入
map<int, string>::iterator iter;
for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++) //遍历
{ Cout<<iter->first<<" "<<iter->second<<end; }
mapStudent.insert(map<int, string>::value_type (1, "student_one")); //插入
map<int, string>::iterator iter;
iter = mapStudent.find(1);//查找
if(iter != mapStudent.end())
{ Cout<<"Find, the value is "<<iter->second<<endl; }
http://www.kuqin.com/cpluspluslib/20071231/3265.html