map用法
来源:互联网 发布:万网独立域名 编辑:程序博客网 时间:2024/06/15 15:33
#include <map>#include <iostream>using namespace std;int main(){ map< string,int > a; cout<<"插入:"<<endl; a["April"]=112;//插入 cout<<a["April"]<<endl; cout<<endl; cout<<"查询:"<<endl; map<string,int>::iterator pc;//查询一个元素是否在map里 pc=a.find("April"); if(pc==a.end()) cout<<"Not Find"<<endl;//如果找不到会自动返回“指向map尾部的迭代器” else cout<<pc->second<<endl;//输出"April"对应的键值 cout<<endl; cout<<"遍历"<<endl; a["June"]=1;//遍历 a["July"]=2; map<string,int>::iterator i; for(i=a.begin(); i!=a.end(); i++)//不能等于a.end() { cout<<i->second<<endl; } cout<<endl; cout<<"判断map是否是空集"<<endl; cout<<a.empty()<<endl;//判断map是否是空集 cout<<endl; cout<<"交换两个map的元素 "<<endl; map<int ,int> b;//交换两个map的元素 map<int ,int> c; c[1]=1; c[2]=2; b[1]=1000; swap(b,c); map<int,int> ::iterator j; for(j=b.begin();j!=b.end();j++) { cout<<j->second<<endl; } for(j=c.begin();j!=c.end();j++) { cout<<j->second<<endl; }}
阅读全文
0 0
- map用法
- map用法
- map用法
- Map用法
- map用法
- Map用法
- map用法
- map用法
- MAP用法
- map用法
- map用法
- map用法
- map 用法
- MAP用法
- map用法
- map用法
- map用法
- map用法
- Javascript删除JSON元素
- fragment_a
- Android -移动互联-依赖
- linux多线程优先级demo
- 用Python和Pygame写游戏-从入门到精通(4)
- map用法
- 单调队列
- jdk版本导致的报错
- mysql 导入sql文件报错no databases select和failed to open file
- Spring Boot整合spring-ws调用web service服务
- fragment_b
- 关于Oracle数据库基于表中某时间字段的范围进行条件查询
- elasticsearch 集群配置
- 设计模式