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, ...
随机推荐
- python各种模块,迭代器,生成器
从逻辑上组织python代码(变量,函数,类,逻辑:实现一个功能) 本质就是.py结尾的python文件(文件名:test.py,对应的模块名就是test) 包:用来从逻辑上组织模块的,本质就是一个目 ...
- SYSAUX表空间如何清理
############################################################ 操作方案################################### ...
- jquery基础学习之DOM篇(二)
在此之前请牢记,jquery 是一个合集对象!!!! 1.节点创建 js创建方法: 创建元素:document.createElement 设置属性:setAttribute 添加文本:innerHT ...
- SQL server 2005数据库的还原与备份
一.SQL数据库的备份: 1.依次打开 开始菜单 → 程序 → Microsoft SQL Server 2005→SQL Server Management Studio ,这里我以UMVTEST命 ...
- cb && cb() 和 a || {}
cb && cb() 等同于 if(cb != undefined) { cb(); } a || {} var flag = false var a = flag || {} a / ...
- 我想要得那块牌—记烟台大学第一届"ACM讲堂"
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/sr19930829/article/details/26812621 2014年 ...
- winform里直接使用WCF,不需要单独的WCF项目
https://www.cnblogs.com/fengwenit/p/4249446.html 依照此法建立即可, 但是vs生成的配置有误,正确配置如下 <?xml version=" ...
- Visual Studio使用Web Deploy远程发布网站及其配置
https://blog.csdn.net/yzj_xiaoyue/article/details/60574378 废话不多说,直接进入正题(各个步骤请看图片的序号): IIS配置 1.打开服务器 ...
- PHP数组和字符串的处理函数汇总
大部分数组处理函数array_chunk — 将一个数组分割成多个array_column — 返回数组中指定的一列array_combine — 创建一个数组,用一个数组的值作为其键名,另一个数组的 ...
- 282A
#include <iostream> #include <string> using namespace std; int main() { int n, plus, sub ...