STL之map::find方法的使用小例子
来源:互联网 发布:js获取android版本号 编辑:程序博客网 时间:2024/05/20 00:17
函数原型
iterator find (const key_type& k);const_iterator find (const key_type& k) const;
返回值
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>.
例子
//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'; std::cout << "b => " << mymap.find('b')->second << '\n'; std::cout << "e => " << mymap.find('e')->second << '\n'; return 0;}
执行结果
Output:elements in mymap:a => 50c => 150d => 200b => 0e => 0
1 0
- STL之map::find方法的使用小例子
- stl之map erase方法的正确使用
- stl之map erase方法的正确使用
- stl之map erase方法的正确使用
- 正确使用stl map的erase方法
- 正确使用stl map的erase方法
- 正确使用stl map的erase方法
- 正确使用stl map的erase方法
- 正确使用stl map的erase方法
- 正确使用stl map的erase方法
- 正确使用stl map的erase方法
- 正确使用stl map的erase方法
- STL中的map使用struct/class作为关键字的例子
- STL之map的基本使用
- STL之MAP的详细使用介绍
- STL库之Map结构的使用
- STL map的使用
- map 的使用【STL】
- 关于python将文本文档以列表方式出现,末尾\n的意思。
- SpringMVC
- oracle--过滤和排序
- Digital Studio
- 剑指offer-39.平衡二叉树
- STL之map::find方法的使用小例子
- Hadoop学习笔记3、Hadoop环境搭建及测试
- 《javascript dom编程艺术》学习笔记
- 第七届蓝桥杯大赛个人赛(软件类)决赛真题
- WIfi
- 手把手教你将Android项目开源到JCenter两种方式以及挖坑和填坑(一)
- 【POJ 2348 Euclid's Game】+ 博弈
- 达夫设备--Duff's Device
- lintcode(662)Guess Number Game