日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

C++ Map用法

發布時間:2025/4/14 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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用法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。