public member function
<map>

std::map::find

      iterator find (const key_type& k);
const_iterator find (const key_type& k) const;
Get iterator to element

Searches the container for an element with a key equivalent to k and returns an iterator to it if found, otherwise it returns an iterator to map::end.

Two keys are considered equivalent if the container's comparison object returns false reflexively (i.e., no matter the order in which the elements are passed as arguments).

Another member function, map::count, can be used to just check whether a particular key exists.

Parameters

k
Key to be searched for.
Member type key_type is the type of the keys for the elements in the container, defined in map as an alias of its first template parameter (Key).

Return value

An iterator to the element, if an element with specified key is found, or map::end otherwise.

If the map object is const-qualified, the function returns a const_iterator. Otherwise, it returns an iterator.

Member types iterator and const_iterator are bidirectional iterator types pointing to elements (of type value_type).
Notice that value_type in map containers is an alias of pair<const key_type, mapped_type>.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// map::find
#include <iostream>
#include <map> int main ()
{
std::map<char,int> mymap;
std::map<char,int>::iterator it; mymap['a']=50;
mymap['b']=100;
mymap['c']=150;
mymap['d']=200; it = mymap.find('b');
if (it != mymap.end())
mymap.erase (it); // print content:
std::cout << "elements in mymap:" << '\n';
std::cout << "a => " << mymap.find('a')->second << '\n';
std::cout << "c => " << mymap.find('c')->second << '\n';
std::cout << "d => " << mymap.find('d')->second << '\n'; return 0;
}

Output:

elements in mymap:
a => 50
c => 150
d => 200

C++ 中map 中迭代器的简单使用:的更多相关文章

  1. C++中Map的使用 (个人简单的对于String的使用)

    #include<map> #include<iostream> #include<string> using namespace std; int main() ...

  2. JS Map 和 List 的简单实现代码

    javascript中是没有map和list 结构的. 本篇文章是对在JS中Map和List的简单实现代码进行了详细的分析介绍,需要的朋友参考下 代码如下: /* * MAP对象,实现MAP功能 *  ...

  3. C++中map的概念,与简单操作

     来源:http://blog.csdn.net/wallwind/article/details/6876892 C++map学习   map<Key, Data, Compare, Allo ...

  4. java中Map,List与Set的区别(转)

    Set,List,Map的区别 java集合的主要分为三种类型: Set(集) List(列表) Map(映射) 要深入理解集合首先要了解下我们熟悉的数组: 数组是大小固定的,并且同一个数组只能存放类 ...

  5. C++中map的基本操作和使用;

    注:本文来自sina live 的博文 Map是c++的一个标准容器,她提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作!1. map最基本 ...

  6. java中Map,List与Set的区别

    Set,List,Map的区别 java集合的主要分为三种类型: Set(集) List(列表) Map(映射) 要深入理解集合首先要了解下我们熟悉的数组: 数组是大小固定的,并且同一个数组只能存放类 ...

  7. [转载]STL map中的一些基本函数

    来源:(http://blog.sina.com.cn/s/blog_61533c9b0100fa7w.html) - C++ map的基本操作和使用_Live_新浪博客 Map是c++的一个标准容器 ...

  8. cocos2d-x3.2中map的基本操作和使用

    在游戏开发中,我们有时候会用到map,而map的使用方法我简单给大家介绍一下.Map是c++的一个标准容器,她提供了非常好一对一的关系,在一些程序中建立一个map能够起到事半功倍的效果,总结了一些ma ...

  9. C++STL中map容器的说明和使用技巧(杂谈)

    1.map简介 map是一类关联式容器.它的特点是增加和删除节点对迭代器的影响很小,除了那个操作节点,对其他的节点都没有什么影响.对于迭代器来说,可以修改实值,而不能修改key. 2.map的功能 自 ...

随机推荐

  1. Matlab中的数据类型

    Matlab中有15种基本数据类型,主要是整型.浮点.逻辑.字符.日期和时间.结构数组.单元格数组以及函数句柄等.         1.整型:(int8:uint8:int16:uint16:int3 ...

  2. 《信息安全系统设计基础》实验五 简单嵌入式WEB服务器实验

    实验报告链接:http://www.cnblogs.com/lx20145332/p/6058790.html

  3. SVPullToRefresh​ 下拉刷新,上拉加载

    https://github.com/Sephiroth87/ODRefreshControl 类似刷新控件,类似qq动画的那种刷新. 一.下载第三方库 https://github.com/samv ...

  4. JS实现星级评价

    说明: 本方法采用了Jquery库,暂时检测兼容IE8版本.本示例的2种颜色的星星都是放入了一张png图片当中,当然还有其他的一些实现思路.本示例展示的情况是当前页面只有一个星级评价的情况. 思路: ...

  5. 20145208 《Java程序设计》第5周学习总结

    20145208 <Java程序设计>第5周学习总结 教材学习内容总结 语法和继承架构 异常处理关键字 第八章内容主要是对Java的异常处理,所以我先了解了一下关键字 Java的异常处理是 ...

  6. python为什么会有@classmethod?

    今天被问了这么个问题 python为什么要有classmethod? 被问倒了,只能回答:classmethod不需要实例化类,用起来比较方便.这么回答没有什么底细,于是查看了一下python的官方文 ...

  7. libusb(.NET)开源项目使用小结

    更多细节请参考官方帮助文档 1,修改设备类型为自己的标识 InfWizard项目里,改掉资源文件LibUsb-Win32-LUDN.Driver.Resources. 原来的三处libusb-win3 ...

  8. 细说C#多线程那些事-线程基础

    我第一次接触“线程”的概念时,觉得它深奥难懂,看了好多本书,花了很长时间才领悟到它的真谛.现在我就以一个初学者的心态,把我所理解的“多线程”描述给大家.这一次是系列文章,比较完整的展示与线程相关的基本 ...

  9. Python数据可视化编程实战——导入数据

    1.从csv文件导入数据 原理:with语句打开文件并绑定到对象f.不必担心在操作完资源后去关闭数据文件,with的上下文管理器会帮助处理.然后,csv.reader()方法返回reader对象,通过 ...

  10. MVC采用HtmlHelper扩展和Filter封装验证码的功能

    最近因为有个项目除了登录还有其他很多地方需要用到验证码的功能,所以想到了采用HtmlHelper和ActionFilter封装一个验证码的功能,以便能够重复调用.封装好以后调用很方便,只需在View中 ...