C++中map用法

2014-11-24 12:39:01 · 作者: · 浏览: 0

/************************************************************************

*

* Map的特点: 1、存储Key-value对

* 2、支持快速查找,查找的复杂度基本是Log(N)

* 3、快速插入,快速删除,快速修改记

*

/************************************************************************/

#include

#include

#include

using namespace std;

int main()

{

map m;

m["a"]=1;

m["b"]=6;

m["c"]=9;

map::iterator it;

it=m.begin();

const char* c =it->first;

cout<<"first element is :"<

int i = m["c"];

while(it!=m.end()){

cout << it->first<<";"<second<

++it;

}

cout <<"m[\"c\"]="<

cout <<"sizeof m:"<

cout <<"erase m[\"c\"](1:succ 0:failed):"<

cout <<"erase m[\"c\"]:"<

cout <<"sizeof m:"<

cout<<"m[c]="<

cout<<"sizeof m :"<

return 0;

}

运行结果

\

低调做人,高调做事

作者 anywei