源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

深入了解C++中map用法

  • 时间:2020-12-15 02:40 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:深入了解C++中map用法
/************************************************************************
*
* Map的特点: 1、存储Key-value对
* 2、支持快速查找,查找的复杂度基本是Log(N)
* 3、快速插入,快速删除,快速修改记[b]*
[/b]/************************************************************************/
#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;

}
[b]运行结果[/b] [img]http://files.jb51.net/file_images/article/201606/20160625094549.jpg[/img] 以上就是小编为大家带来的深入了解C++中map用法全部内容了,希望大家多多支持编程素材网~
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部