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, ...
随机推荐
- ORACLE监听配置及测试实验(2)
实验四 在tnsname.ora里添加默认监听代号 [oracle@oracle01 admin]$ vi tnsnames.ora 添加一行 PORT1528=(ADDRESS = (PROTOCO ...
- selenium+xpath在不同层级的写法
总结:定位虽然用Inndex定位最快,但是定位最好不要用浏览器自带定位xpath,尽量不要用Index,否则写的UI自动化脚本的定位元素,需要重新维护.代价太大. 一:不在同一层级,可以用[./..] ...
- POJ2274 Long Long Message 字符串
正解:SA/哈希+二分 解题报告: 传送门! 啊先放下翻译,,,?大意就有两个字符串,求这两个字符串的最长公共子串 先港SA的做法趴 就把两个子串拼接起来,然后题目就变成了求后缀的最长公共前缀了 所以 ...
- bug: '\xff' 转换成-1 而不是255
后台给的值处理后 Byte rtncode = payload[0]; 打印payload[0]是'\xff', 增加 if (rtncode ==255 ){ ....} 的判断,跳里面去了 然后用 ...
- es分布式文档系统_bulk api的奇特json格式与底层性能优化关系
1.bulk api奇特的json格式{"action":{"meta"}}\n{"data"}\n{"action": ...
- 10.1-uC/OS-III任务堆栈空间
1.设置任务优先级 嵌入式系统中的重要的应用应该被设置为高优先级,一些显示操作就应该被设置为低优先级. 然而, 由于实时系统的复杂性, 在大多数情况下任务的优先级是不能被事先确定的.多数系统中,不是所 ...
- django基础-01:软件框架,MVC框架,MVT
1. 软件框架 一个公司是由公司中的各部部门来组成的,每一个部门拥有特定的职能,部门与部门之间通过相互的配合来完成让公司运转起来. 一个软件框架是由其中各个软件模块组成的,每一个模块都有特定的功能,模 ...
- mysql 初识sql语句
有了mysql这个数据库软件,就可以将程序员从对数据的管理中解脱出来,专注于对程序逻辑的编写 mysql服务端软件即mysqld帮我们管理好文件夹以及文件,前提是作为使用者的我们,需要下载mysql的 ...
- mysql 操作sql语句 目录
mysql 操作sql语句 操作数据库 mysql 操作sql语句 操作数据表 mysql 操作sql语句 操作数据表中的内容/记录
- vue-3.0创建项目
.npm install --global @vue/cli .npm install -g @vue/cli-init .vue init webpack my-project