map 的用法
#include<iostream>
#include<map>
#include<string> #define s second
#define f first using namespace std;
// map 的构造
map<int , int> ii;
map<string , string> ss;
map<string , int> si;
typedef map<int , string> mapType;
mapType is; int main()
{
// map 的插入方法 1 用insert函数插入value_type数据
ii.insert(map<int, int >::value_type(,));
ii.insert(map<int , int >::value_type(,));
ii.insert(map<int , int >::value_type(,));
cout << "ii : " << endl << ii.size() << endl;
for(map<int , int>::iterator it = ii.begin(); it != ii.end(); it++)
cout << "key : " << it->f << " value : " << it->s << endl;
// map 的插入方法 2 用insert函数插入pair数据
ss.insert(pair<string, string>("a", "a"));
ss.insert(pair<string, string>("b", "b"));
ss.insert(pair<string, string>("c", "c"));
cout << "ss : " << endl << ii.size() << endl;
for(map<string , string>::iterator it = ss.begin(); it != ss.end(); it++)
cout << "key : " << it->f << " value : " << it->s << endl;
// map 的插入方法 3 用insert函数插入make_pair数据
si.insert(make_pair<string, int>("a",));
si.insert(make_pair<string, int>("b",));
si.insert(make_pair<string, int>("c",));
cout << "si : " << endl << si.size() << endl;
for(map<string , int>::iterator it = si.begin(); it != si.end(); it++)
cout << "key : " << it->f << " value : " << it->s << endl;
// map 的插入方法 4 用数组插入
ii[] = ;
ii[] = ;
ii[] = ;
ii[] = ;
cout << "ii : " << endl << ii.size() << endl;
for(map<int , int>::iterator it = ii.begin(); it != ii.end(); it++)
cout << "key : " << it->f << " value : " << it->s << endl;
// 前三种方法后面的值不会覆盖前面的值
// 查找方法 1
// count函数求的是关键字key的个数?key是不能重复的,所以返回只有0和1两种结果。
cout << "查找关键字1的结果 : " << ii.count() << endl;
cout << "查找关键字1的结果 : " << ii.count() << endl;
cout << "查找关键字a的结果 : " << ss.count("a") << endl;
cout << "查找关键字a的结果 : " << si.count("c") << endl;
//查找方法 2
map<string, int>::iterator it;
it = si.find("c");
if(it != si.end())
cout << "find it : " << it->s << endl;
else
cout << "not find" << endl; }
map 的用法的更多相关文章
- c++map的用法 分类: POJ 2015-06-19 18:36 11人阅读 评论(0) 收藏
c++map的用法 分类: 资料 2012-11-14 21:26 10573人阅读 评论(0) 收藏 举报 最全的c++map的用法 此文是复制来的0.0 1. map最基本的构造函数: map&l ...
- STL中map的用法
map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候 ...
- C++11中map的用法
最全的c++map的用法 1. map最基本的构造函数:map<string ,int>mapstring; map<int,string >mapint;map<sri ...
- entrySet用法 以及遍历map的用法
entrySet用法 以及遍历map的用法 keySet是键的集合,Set里面的类型即key的类型entrySet是 键-值 对的集合,Set里面的类型是Map.Entry 1.keySet( ...
- python map 常见用法
python map 常见用法2017年02月01日 19:32:41 淇怪君 阅读数:548版权声明:欢迎转载,转载请注明出处 https://blog.csdn.net/Tifficial/art ...
- 8 map的用法
what's map go里面的map和python字典差不多. 类似其他语言中的哈希表或者字典,以key-value的形式存储的数据 key必须是支持==或者!=比较运算的类型,不可以是函数.map ...
- forEach、for+i、map的用法及区别
array.forEach(callback[, thisObject]); 下面是参数的详细信息: 1. callback : 函数测试数组的每个元素. 2.thisObject : 对象作为该 ...
- set/multiset和map/multimap用法小结
二叉搜索树是ACM中经常需要用到的数据结构,熟练掌握map和set的用法很关键,现对其做一个简单的总结. 主要的功能有:插入元素,查找元素,删除,遍历/反向遍历. 插入,删除和查找操作的时间都和树的高 ...
- STL 之 map的用法
Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候 ...
- js数组中foEach和map的用法详解 jq中的$.each和$.map
数组中foEach和map的用法详解 相同点: 1.都是循环遍历数组(仅仅是数组)中的每一项. 2.forEach() 和 map() 里面每一次执行匿名函数都支持3个参数:数组中的当前项value, ...
随机推荐
- LeetCode 872 Leaf-Similar Trees 解题报告
题目要求 Consider all the leaves of a binary tree. From left to right order, the values of those leaves ...
- 2018/09/05《涂抹MySQL》【权限管理】学习笔记(二)
读 第四章<管理MySQL库与表> 第五章<MySQL的权限管理> 总结 1:当配置好 MySQL 数据库后,发现有几个默认的库,他们的意义和作用?(这里只做简单了解,之后用到 ...
- Java+selenium 如何定位下拉框select
场景:需要进行下拉选择定位元素. 一.select菜单 select也是比较常见的,selenium封装了以下方法, 创建select WebElement selector = dr ...
- 给予Java初学者的学习路线建议
va学习这一部分其实也算是今天的重点,这一部分用来回答很多群里的朋友所问过的问题,那就是你是如何学习Java的,能不能给点建议?今天我是打算来点干货,因此咱们就不说一些学习方法和技巧了,直接来谈每个阶 ...
- Log4j Append属性指定是否追加内容
Log4j默认是不断的把日志内容追加到日志文件: 这里就有个属性 Append 默认就是true: 假如我们设置成false 就不追加了 直接覆盖前面的内容: 我们来测试下: log4j.rootLo ...
- 1-3-编译Linux内核
1-3-编译Linux内核 1.将Linux源码包拷贝到共享文件夹. 2.进入共享文件夹. 3.解压,命令#tar xvfj Kernel_3.0.8_TQ210_for_Linux_v2.2.tar ...
- gitlab数据库
event表中action对应操作: 1 - 新建项目 5 - push 8 - 在某项目中赋予某人权限 9 - 在某项目中取消某人权限
- wordpress如何去掉generator
用wordpress建站经常会出现一些显而易见的标签,比如说作者<meta name="generator" content="WordPress 4.9" ...
- LVS小型系统架构搭建笔记
搭建环境说明 本次实现用到了6台节点,实现一个小型的Lvs负载调度 节点1客户端配置代表互联网用户 [root@centos7 network-scripts]# vi ifcfg-ens37 TYP ...
- c#NamedPipe命名管道通信例子
服务端 private NamedPipeServerStream pipeServer; private Thread receiveDataThread = null; public fServe ...