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, ...
随机推荐
- 转:jquery的$(function(){})和$(document).ready(function(){}) 的区别
原文链接:https://www.cnblogs.com/slyzly/articles/7809935.html [转载]jquery的$(function(){})和$(document).rea ...
- ef 数据库创建失败
在ef之前创建了一个数据库,然后删除后,再用ef创建,失败! USE [master] GO /****** Object: Database [DBname] ******/ ALTER DATAB ...
- centos安装Django之二:pip3安装
前面我们说到了centos安装Django之一:安装openssl,现在我们进入第二阶段pip3安装.两步实现:安装setuptools(pypi),安装pip,下面就和ytkah一起看看配置吧 1. ...
- iOS开发swift语法0基础篇—————(swift技术交流群:361513739)
iOS开发之swift语法0基础篇:点击打开链接 swift技术交流QQ群361513739
- python如何使用request爬取图片
下面是代码的简单实现,变量名和方法都是跑起来就行,没有整理,有需要的可以自己整理下: image2local: import requests import time from lxml import ...
- Got timeout reading communication packets解决方法
Got timeout reading communication packets解决方法 http://www.th7.cn/db/mysql/201702/225243.shtml [Note] ...
- MySQL表操作及数据操作
表操作 表相当于一个文件,其形式与现实中的表格相同.表中的每条记录都有相应的字段,字段就类似于表格的表头. 表操作详细: #对表进行操作(文件) #首先要切换到指定库(即文件夹)下:use db1; ...
- Python3学习之路~6.8 多态
多态性(polymorphisn)是允许你将父对象设置成为和一个或更多的他的子对象相等的技术,赋值之后,父对象就可以根据当前赋值给它的子对象的特性以不同的方式运作.简单的说,就是一句话:允许将子类类型 ...
- ansible进阶模板和角色使用
使用场景 Ansible 由于采用ssh远程连接登录管理,虽然不需要额外安装agent,但是速度慢效率低.不适合管理大规模的主机一般最大规模在200-300台,超大规模的主机管理适合使用puppet ...
- vue ie
http://www.jb51.net/article/118792.htm https://blog.csdn.net/landl_ww/article/details/79149461 解决 安装 ...