深刻懂得C++中map用法。本站提示廣大學習愛好者:(深刻懂得C++中map用法)文章只能為提供參考,不一定能成為您想要的結果。以下是深刻懂得C++中map用法正文
/************************************************************************
*
* 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;
}
運轉成果
以上就是小編為年夜家帶來的深刻懂得C++中map用法全體內容了,願望年夜家多多支撐~