雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

深入了解C++中map用法

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊:

/************************************************************************
*
* Map的特點: 1、存儲Key-value對
* 2、支持快速查找,查找的復(fù)雜度基本是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;

}

運行結(jié)果

以上就是小編為大家?guī)淼纳钊肓私釩++中map用法全部內(nèi)容了,希望大家多多支持我們~

上一篇:大數(shù)據(jù)情況下桶排序算法的運用與C++代碼實現(xiàn)示例

欄    目:C語言

下一篇:C語言求矩陣的各列元素之和的代碼示例

本文標(biāo)題:深入了解C++中map用法

本文地址:http://www.jygsgssxh.com/a1/Cyuyan/2204.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有