ANYWEI : CODING

积累点滴,成就梦想

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

/************************************************************************
*
* Map的特点: 1、存储Key-value对
* 2、支持快速查找,查找的复杂度基本是Log(N)
* 3、快速插入,快速删除,快速修改记
*
/************************************************************************/
#include <iostream>
#include <string>
#include <map>
using namespace std;


int main()
{
map<const char*,int> m;
m["a"]=1;
m["b"]=6;
m["c"]=9;
map<const char*,int>::iterator it;
it=m.begin();
const char* c =it->first;
cout<<"first element is :"<<c<<endl;
int i = m["c"];
while(it!=m.end()){
cout << it->first<<";"<<it->second<<endl;
++it;
}
cout <<"m[\"c\"]="<<i<<endl;
cout <<"sizeof m:"<<m.size()<<endl;
cout <<"erase m[\"c\"](1:succ 0:failed):"<<m.erase("c")<<endl;
cout <<"erase m[\"c\"]:"<<m.erase("c")<<endl;
cout <<"sizeof m:"<<m.size()<<endl;
cout<<"m[c]="<<m["c"]<<endl;
cout<<"sizeof m :"<<m.size()<<endl;

return 0;

}

运行结果

posted on 2011-10-27 20:56  anywei  阅读(16918)  评论(1编辑  收藏  举报