手机
当前位置:查字典教程网 >编程开发 >C语言 >深入了解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用法1

以上就是小编为大家带来的深入了解C++中map用法全部内容了,希望大家多多支持查字典教程网~

【深入了解C++中map用法】相关文章:

浅析STL中的常用算法

深入C++中struct与class的区别分析

c++中inline的用法分析

深入理解C++的多态性

关于C/C++中typedef的定义与用法总结

深入分析C++中几个最不常用的关键字

C中的volatile使用方法

c语言B树深入理解

浅析C语言中assert的用法

深入分析C++中类的大小

精品推荐
分类导航