STL find() ,还是挺重要的
template<class InputIterator, class T>
InputIterator find (InputIterator first, InputIterator last, const T& val)
{
while (first!=last) {
if (*first==val) return first;
++first;
}
return last;
}
http://www.cplusplus.com/reference/algorithm/find/
// find example
#include <iostream> // std::cout
#include <algorithm> // std::find
#include <vector> // std::vector int main () {
int myints[] = { , , , };
int * p; // pointer to array element:
p = std::find (myints,myints+,);
++p;
std::cout << "The element following 30 is " << *p << '\n'; std::vector<int> myvector (myints,myints+);
std::vector<int>::iterator it; // iterator to vector element:
it = find (myvector.begin(), myvector.end(), );
++it;
std::cout << "The element following 30 is " << *it << '\n'; return ;
}
Output:
The element following 30 is 40
The element following 30 is 40
STL find() ,还是挺重要的的更多相关文章
- dijkstra的stl实现(最近觉得挺方便的
dijkstra的stl实现(最近觉得挺方便的 stl可作为跳板 --- Rujia liu struct node { int dis, id; node(int dis = 0, int id = ...
- C++ STL模板
C++中的STL(Standard Template Library)用起来挺方便的,这里我们来做一下总结. 一.set set是STL中一种标准关联容器 (vector,list,string,de ...
- STL之序列容器vector
首先来看看vector的模板声明: template <class T, class Alloc = allocator<T>> class vector { //… }; v ...
- DLL中传递STL参数(如Vector或者list等)会遇到的问题[转载]
最近的一个项目中遇到了调用别人的sdk接口(dll库)而传给我的是一个vector指针,用完之后还要我来删除的情况.这个过程中首先就是在我的exe中将其vector指针转为相应指针再获取vector中 ...
- STL学习之路
本文面向的读者:学习过C++程序设计语言(也就是说学习过Template),但是还没有接触过STL的STL的初学者.这实际上是我学习STL的一篇笔记,老鸟就不用看了. 什么是泛型程序设计 我们可以简单 ...
- C++ STL 学习 :for_each与仿函数(functor)
简单来将,仿函数(functor)就是一个重载了"()"运算符的struct或class,利用对象支持operator()的特性,来达到模拟函数调用效果的技术. 我们平时对一个集合 ...
- stl 迭代器(了解)
STL 主要是由 containers(容器),iterators(迭代器)和 algorithms(算法)的 templates(模板)构成的. 对应于它们所支持的操作,共有五种 iterators ...
- STL源码分析《3》----辅助空间不足时,如何进行归并排序
两个连在一起的序列 [first, middle) 和 [middle, last) 都已经排序, 归并排序最核心的算法就是 将 [first, middle) 和 [middle, last) 在 ...
- 智能指针(一):STL auto_ptr实现原理
智能指针实际上是一个类(class),里面封装了一个指针.它的用处是啥呢? 指针与内存 说到指针自然涉及到内存.我们如果是在堆栈(stack)中分配了内存,用完后由系统去负责释放.如果是自定义类型,就 ...
随机推荐
- Headfirst设计模式的C++实现——外观模式(Facade)
light.h #ifndef _LIGHT_H_ #define _LIGHT_H_ #include <iostream> class LIGHT { public: void dim ...
- 省市选择(基于zepto.js)
效果如下: <div class="clList overflow-h mt75"> <select class="pull-left cl-35 se ...
- RasAPI函数实现PPPOE拨号
unit uDial; interface uses Windows,Messages, SysUtils, Ras;// Classes; var //EntryName,UserName,Pass ...
- Linux下GPIO驱动(五) ----misc_register();
// struct miscdevice { int minor; const char *name; const struct file_operations *fops; struct list_ ...
- 深度(Depth)概念
强化对深度的理解 在老版本的NGUI中,UI的显示层次关系是依靠z轴进行的.在新版本的NGUI中,所有UI的z轴都被统一,然后用深度来决定和管理显示的层次关系.关于深度,要记住一下关键点: 1.每一个 ...
- CODEVS 1004四子连棋
[题目描述 Description] 在一个4*4的棋盘上摆放了14颗棋子,其中有7颗白色棋子,7颗黑色棋子,有两个空白地带,任何一颗黑白棋子都可以向上下左右四个方向移动到相邻的空格,这叫行棋一步,黑 ...
- ios音频视频资料--备用
视频播放 MediaPlayer.framework MPMoviePlayerViewController VS MPMoviePlayerController MPMoviePlayerViewC ...
- Windows获取其他进程中Edit控件的内容
最近做的MFC项目中,有个获取其他进程中Edit控件内容的需求,本来以为是个很简单的问题,但是来来回回折腾了不少时间,发博记录一下. 刚开始拿到这个问题,很自然的就想到GetDlgItemText() ...
- oracle数据库的建表,删除字段,添加字段,修改字段,修改字段......
1. 使用oracle创建一张表: SQL> create table loginuser( id ,), username ), password ), email ), descriable ...
- 递归解析XML
package com.app.test; import java.io.InputStream; import java.util.List; import org.dom4j.Attribute; ...