C++每日一练(STL算法——find)
来源:互联网 发布:怎样查看淘宝购买记录 编辑:程序博客网 时间:2024/06/06 08:34
一、今日课题
find
二、实战演练
template <class InputIterator, class T>InputIterator find (InputIterator first, InputIterator last, const T& val);
1)有何用?
利用底层元素的等于操作符,对指定范围内的元素与输入值进行比较。当匹配时,结束搜索,返回该元素的一个InputIterator。
2)怎么用?
// find example#include <iostream> // std::cout#include <algorithm> // std::find#include <vector> // std::vectorint main () { // using std::find with array and pointer: int myints[] = { 10, 20, 30, 40 }; int * p; p = std::find (myints, myints+4, 30); if (p != myints+4) std::cout << "Element found in myints: " << *p << '\n'; else std::cout << "Element not found in myints\n"; // using std::find with vector and iterator: std::vector<int> myvector (myints,myints+4); std::vector<int>::iterator it; it = find (myvector.begin(), myvector.end(), 30); if (it != myvector.end()) std::cout << "Element found in myvector: " << *it << '\n'; else std::cout << "Element not found in myvector\n"; return 0;}
三、C++树
10/28/2016 5:46:07 PM
0 0
- C++每日一练(STL算法——find)
- C++每日一练(STL算法——sort)
- C++每日一练(STL算法——copy)
- C++每日一练(STL算法——remove)
- C++每日一练(STL算法——for each)
- 算法每日一练
- 20171020—每日一练
- 20171019—每日一练
- 算法每日一练1
- java算法每日一练
- C语言每日小练(一)——7744问题
- C语言每日小练(一)——3n+1问题
- C语言每日小练(一)——n!问题
- vim每日一练(三)——查找匹配
- 每日一练(8)—— 野指针
- 每日一练——2016.2.24
- 每日一练——2016.2.25
- 每日一练——H-Index
- 231. Power of Two
- 对一个二维数组中的数据排序,方法如下: 将整个数组中值最小的元素所在行调整为数组第一行, 将除第一行外的行中最小元素所在行调整为第2行, 将除第1,2行外的行中最小值元素所在行调整为第3行,以此类推
- java从数据库读取菜单,递归生成菜单树
- idea中配置git信息
- FreeType 源码编译
- C++每日一练(STL算法——find)
- IO流之字节流
- 如何考察求职者的「学习能力」?求职者如何培养学习能力?
- rsyslog+loganalyzer+evtsys搭建集中式监控系统
- java中 null和“”的区别详解
- json在scala开发中的应用
- [lib3ds] 开源3ds文件解析库(一):基础
- mfc中普通函数调用类的成员函数或者mfc类库中的函数
- CSS-伪类学习