简单的程序诠释C++ STL算法系列之二:find
来源:互联网 发布:2017好玩的3d网络手游 编辑:程序博客网 时间:2024/05/17 05:13
C++STL的非变易算法(Non-mutating algorithms)是一组不破坏操作数据的模板函数,用来对序列数据进行逐个处理、元素查找、子序列搜索、统计和匹配。
find算法用于查找等于某值的元素。它在迭代器区间[first , last)上查找等于value值的元素,如果迭代器iter所指的元素满足 *iter == value ,则返回迭代器iter,未找则返回last。
函数原型:
- template<class InputIterator, class Type>
- InputIterator find(
- InputIterator _First,
- InputIterator _Last,
- const Type& _Val
- );
示例代码:
- /*******************************************************************
- * Copyright (C) Jerry Jiang
- * File Name : find.cpp
- * Author : Jerry Jiang
- * Create Time : 2011-9-29 0:03:25
- * Mail : jbiaojerry@gmail.com
- * Blog : http://blog.csdn.net/jerryjbiao
- * Description : 简单的程序诠释C++ STL算法系列之二
- * 非变易算法 : 查找容器元素find
- ******************************************************************/
- #include <algorithm>
- #include <list>
- #include <iostream>
- using namespace std;
- int main()
- {
- list<int> ilist;
- for (size_t i = 0; i < 10; ++i)
- {
- ilist.push_back(i+1);
- }
- ilist.push_back(10);
- list<int>::iterator iLocation = find(ilist.begin(), ilist.end(), 10);
- if (iLocation != ilist.end())
- {
- cout << "找到元素 10" << endl;
- }
- cout << "前一个元素为:" << *(--iLocation) << endl;
- return 0;
- }
*******************************************************************************************************************************
C++经典书目索引及资源下载:http://blog.csdn.net/jerryjbiao/article/details/7358796
********************************************************************************************************************************
- 简单的程序诠释C++ STL算法系列之二:find
- 简单的程序诠释C++ STL算法系列之二:find
- 简单的程序诠释C++ STL算法系列之二:find
- 简单的程序诠释C++ STL算法系列: find & find_if
- 简单的程序诠释C++ STL算法系列之一:for_each
- 简单的程序诠释C++ STL算法系列之一:for_each
- 简单的程序诠释C++ STL算法系列之一:for_each
- 简单的程序诠释C++ STL算法系列之三:find_if
- 简单的程序诠释C++ STL算法系列之四:adjacent_find
- 简单的程序诠释C++ STL算法系列之五:find_first_of
- 简单的程序诠释C++ STL算法系列之六:count
- 简单的程序诠释C++ STL算法系列之七:count_if
- 简单的程序诠释C++ STL算法系列之八:mismatch
- 简单的程序诠释C++ STL算法系列之九:equal
- 简单的程序诠释C++ STL算法系列之十:search
- 简单的程序诠释C++ STL算法系列之十一:search_n
- 简单的程序诠释C++ STL算法系列之十二:find_end
- 简单的程序诠释C++ STL算法系列之十三:copy
- Java格式化输出日期
- 55js
- 简单的程序诠释C++ STL算法系列之一:for_each
- android WebView 与 HttpClient Cookie
- 5秒后跳转到另一个页面
- 简单的程序诠释C++ STL算法系列之二:find
- oracle用户创建及权限设置
- CUDA矩阵BLAS效率
- (+)第104天的交易(2013-10-11)(-50)(43.57)(数据单总盈利:474.6)(贵金属总盈利:-489.92)
- java 递归模式 遍历给定文件
- StackOverflow 并不只是一个问答网站
- CMD命令工具--Windows下使用tree命令生成目录
- 修改Android解锁界面
- 多线程