cb31a_c++_STL_算法_查找算法_(4)find_first_of
find_first_of(b,e,sb,se),sb,second begin, se,second end();
find_first_of(b,e,sb,se,bp),bp--谓词,就是一个函数,或者函数对象,返回一个bool

使用逆向迭代器,实现string类的rfind.找最后一个。reverse_find=rfind
没有find_last_of算法,string类的成员函数有find_last_of

find()
find_if()
search_in()
serarch()
find_end()
find_first_of()
adjacent_find()
txwtech@163.com

 /*cb31a_c++_STL_算法_查找算法_(4)find_first_of
find_first_of(b,e,sb,se),sb,second begin, se,second end();
find_first_of(b,e,sb,se,bp),bp--谓词,就是一个函数,或者函数对象,返回一个bool 使用逆向迭代器,实现string类的rfind.找最后一个。reverse_find=rfind
没有find_last_of算法,string类的成员函数有find_last_of find()
find_if()
search_in()
serarch()
find_end()
find_first_of()
adjacent_find()
txwtech@163.com
*/ #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string> using namespace std; int main()
{
vector<int> ivec;
list<int> searchList;
for (int i = ; i <= ; ++i)
{
ivec.push_back(i);
}
for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); ++iter)
cout << *iter << ' ';
cout << endl;
searchList.push_back();
searchList.push_back();
searchList.push_back(); cout << "ivec里面找,3,6,9" << endl;
vector<int>::iterator pos;
pos=find_first_of(ivec.begin(), ivec.end(), searchList.begin(), searchList.end());
if (pos != ivec.end())
cout << "找到了,位置是:" << distance(ivec.begin(), pos) + << endl;
else
cout << "没找到" << endl; vector<int>::reverse_iterator rpos;
// rpos.base(),转换成正向迭代器,就不需要加1了
rpos= find_first_of(ivec.rbegin(), ivec.rend(), searchList.begin(), searchList.end());
if (rpos != ivec.rend())
cout << "逆向迭代器找到了,位置是:" << distance(ivec.begin(), rpos.base()) << endl;
else
cout << "没找到" << endl; string numerics("");
string name("ra82d3k"); cout << "name里面找numerics的内容" << endl;
string::size_type posn= name.find_first_of(numerics);//顺序查找
if (posn != string::npos)
cout << "posn不等于npos,npos表示结束位置,已经扎到了,下标:" << posn << endl;
else
cout << "没找到" << endl; posn = name.find_last_of(numerics);//逆向查找
if (posn != string::npos)
cout << "逆向查找,最后一位开始找,已经扎到了,下标:" << posn << endl;
else
cout << "没找到" << endl; return ;
}

cb31a_c++_STL_算法_查找算法_(4)find_first_of的更多相关文章

  1. cb34a_c++_STL_算法_查找算法_(7)_lower_bound

    cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置uppe ...

  2. cb33a_c++_STL_算法_查找算法_(6)binary_search_includes

    cb33a_c++_STL_算法_查找算法_(6)binary_search_includes//针对已序区间的查找算法,如set,multiset关联容器-自动排序binary_search(b,e ...

  3. cb32a_c++_STL_算法_查找算法_(5)adjacent_find

    cb32a_c++_STL_算法_查找算法_(5)adjacent_findadjacent_find(b,e),b,begin(),e,end()adjacent_find(b,e,p),p-par ...

  4. cb30a_c++_STL_算法_查找算法_(3)search_find_end

    cb30a_c++_STL_算法_查找算法_(3)search_find_endsearch()pos = search(ideq.begin(), ideq.end(), ilist.begin() ...

  5. cb29a_c++_STL_算法_查找算法_(2)search_n

    cb29a_c++_STL_算法_查找算法_(2)search_n//比如:连续查找连续的n个8search_n(b,e,c,v),迭代器b,begin(),e,end().连续的c个vpos=sea ...

  6. cb28a_c++_STL_算法_查找算法_(1)find_find_if

    cb28a_c++_STL_算法_查找算法_(1)find_find_iffind() //线性查找,比较慢.pos1 = find(ilist.begin(), ilist.end(), 5);fi ...

  7. STL_算法_查找算法(lower_bound、upper_bound、equal_range)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n)))    已序区间查找算法 lower_bound()        //找第一个符合的 ...

  8. STL_算法_查找算法(find、find_if)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...

  9. STL_算法_查找算法(binary_search、includes)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n)))     已序区间查找算法 binary_search             //二分查 ...

随机推荐

  1. Django + Celery 实现动态配置定时任务

    哈喽,今天给大家分享一篇Django+Celery实现动态配置定时任务,因为最近也是无意间看到一位大佬关于这块的文章,然后自己觉得不错,也想学习写一下,然后最终实现功能是在前端页面统一管理计划任务,大 ...

  2. APP元素定位和操作

    webdriver 提供了八种元素定位方法: 在 Python 语言中对应的定位方法如下:find_element_by_id()find_element_by_name()find_element_ ...

  3. Android启动过程_大致流程

    Android大致启动过程如图(基于O版本  使用draw.io画的). 注:这是通过查询结合自己了解的,还有不少不明确的,后续有进展完善,欢迎指正. 说明:绿色是主要几个的阶段.其他围绕这几个阶段的 ...

  4. [Python基础]007.字符串

    字符串 内建操作 字符串长度 大小写变换 去空格或其他 连接字符串 查找替换 分割 判断 内建操作 字符串长度 len 代码 s = 'abcd' print len(s) 大小写变换 lower 小 ...

  5. 正则表达式:匹配单个数字重复n次

    匹配单个数字重复n次:(\d)\1{n-1}其中,\d表示一位数字,(\d)表示匹配之后捕获该匹配,并分组并对组进行编号\1表示被捕获的第一个分组{n-1}是因为被捕获的第一个分组已经消耗了一位数字, ...

  6. 【asp.net core 系列】 1 带你了解一下asp.net core

    0. 前言 这是一个新的系列,名字是<ASP.NET Core 入门到实战>.这个系列主讲ASP.NET Core MVC,辅助一些前端的基础知识(能用来实现我们需要的即可,并非主讲).同 ...

  7. 经典卷积神经网络算法(3):VGG

    .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...

  8. jchdl - GSL实例 - Mux4(使用Mux)

    https://mp.weixin.qq.com/s/GrYJ4KXEFRoLLmLnAGoMSA 原理图 ​​ 参考链接 https://github.com/wjcdx/jchdl/blob/ma ...

  9. Chisel3-Intellij IDEA中使用sbt构建Chisel项目

    https://mp.weixin.qq.com/s/gssjiiPW6zUzKwCFZdNduw   1. 使用Intellij IDEA创建Scala项目   Chisel项目,就是构建Scala ...

  10. “造轮运动”之 ORM框架系列(二)~ 说说我心目中的ORM框架

    ORM概念解析 首先梳理一下ORM的概念,ORM的全拼是Object Relation Mapping (对象关系映射),其中Object就是面向对象语言中的对象,本文使用的是c#语言,所以就是.ne ...