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

最新文章

  1. bzoj[3238][ahoi差异]
  2. hibernate中load和get方法的区别
  3. poj1274 The Perfect Stall (二分最大匹配)
  4. android 合并两个jar包
  5. Tomcat7 安装StartSSL证书笔记
  6. JAVA动态加载JAR包的实现
  7. Oracle11g使用exp导出空表
  8. jar,war,ear区别及java基础杂七八
  9. VJ1061迎春舞会之三人组舞
  10. Linux指令--kill
  11. 接口自动化框架(java)--1.项目概述
  12. dockerfile编辑时常用的sed命令,用来修改配置文件。
  13. Linux与Windows的几点区别
  14. SQL开发规范
  15. python beautifulsoup爬虫学习
  16. 51nod 1295 XOR key 可持久化01字典树
  17. PHP 代 码 操 作 文 件
  18. Oracle的下载安装教程以及所出现的问题
  19. ionic3 打包一个已签名的apk
  20. Mac逆向--思维导图

热门文章

  1. matlab建立双坐标
  2. Linux常用指令---系统管理
  3. IOS开发之——自定义导航控制器
  4. git的简介,安装以及使用
  5. Vs2012 中使用itoa
  6. 【java基础】IOC介绍及其简单实现
  7. 慢牛系列四:好玩的React Native
  8. JavaScript基础2---控制权DOM操作
  9. 使用TinkPHP实现品字形布局
  10. IOS 计算两个经纬度之间的距离