C++中map用法(一)
来源:互联网 发布:洛神花果酱淘宝 编辑:程序博客网 时间:2024/05/07 18:42
- 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用法(一)
- Map用法详解(一)
- [C++]STL中map的用法
- HDU1004(C++map的用法)
- c++STL map用法(转)
- c++map的用法
- c++map的用法
- C++map用法
- c++map的用法
- C++map的用法
- c++map的用法
- c++map的用法
- c++Map的用法
- C++map容器用法
- C语言中少见的用法(一):define
- JSTL中C标签的简单用法(一)
- STL中map用法详解 (转)
- STL中map用法详解(转)
- 三字经(拼音版)
- 使用subprocess.open
- 在jsp中js jquery点击按钮出现一个对话框的实现
- ubuntu gcc 编译全过程
- 串联电阻
- C++中map用法(一)
- Java深拷贝对象
- 单击头模板中的checkbox,实现datalist中所有chebox的全选和取消
- java如何去除字符串前面的0
- Objective C--简单工厂模式
- 《汉语拼音方案》缺陷与修正
- tiff文件读取
- C# 扩展方法实际应用整理
- UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath