1.首先使用map需要

#include<map>
2.map的构造函数为
Map<key,value> arrayName;
如果想建立关键字为int型,以string型为数据元的数组(数组其实更容易理解)则:
Map<intstring> mapStudent;
3.三种插入方式:
用insert方法插入pair对象:
mapStudent.insert(pair<intstring>(1, “student_one”));

用insert方法插入type_value对象:
mapStudent.insert(map<intstring>::value_type (1, “student_one”));

用数组方式插入值:
mapStudent[1=  “student_one”;

4.数组的大小:
Int nSize = mapStudent.size();

5.三种遍历方式:
用迭代器正向遍历:
定义迭代器:
map<intstring>::iterator  iter; 

 

正向遍历:

for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
    Cout
<<iter->first<<”   ”<<iter->second<<end;

用反向迭代器反向遍历:
定义反向迭代器
map<intstring>::reverse_iterator  iter;

反向遍历
for(iter = mapStudent.rbegin(); iter != mapStudent.rend(); iter++)
       Cout
<<iter->first<<”   ”<<iter->second<<end;
用数组方式查看:
for(int i=0;i<mapStudent.size();i++)cout<<mapStudent[i]<<endl;


这些对我基本够用,如果要求更详细可以参考:
http://www.kuqin.com/cpluspluslib/20071231/3265.html


Posted on 2009-01-20 01:04 JimmyZhang 阅读(658) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理