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. JedisPool的使用-连接池

    为什么要使用JedisPool 1,获取Jedis实例需要从JedisPool中获取 2,用完Jedis实例需要返还给JedisPool 3,如果Jedis在使用过程中出错,则也需要还给JedisPo ...

  2. 剑指Offer之跳台阶

    题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果). 解法1:递归解法 public int JumpFloor(int t ...

  3. [Python基础]003.语法(2)

    语法(2) 运算符 数学运算 比较运算 逻辑运算 位运算 赋值运算 其他运算 代码规范 代码缩进 多行 注释 流程控制 pass if while for break continue 运算符 数学运 ...

  4. win10系统下计算器界面变成英文的解决方法

    标题: win10系统下计算器界面变成英文的解决方法 作者: 梦幻之心星 347369787@QQ.com 标签: [win10, 计算器, 英文] 目录: 软件 日期: 2019-04-20 目录 ...

  5. RabbitMQ安装(centos7)

    本文是作者原创,版权归作者所有.若要转载,请注明出处. 本文RabbitMQ版本为rabbitmq-server-3.7.17,erlang为erlang-22.0.7.请各位去官网查看版本匹配和下载 ...

  6. Matlab矩阵学习二 矩阵的修改

    Matlab矩阵的修改 一.元素修改 (1).矩阵扩充   (2)矩阵删除某行或某列 删除某行:A(m,:)=[]   %删除A矩阵的第m行   删除某列: A(:,n)=[] %删除A矩阵的第n列 ...

  7. 50个SQL语句(MySQL版) 问题十三

    --------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...

  8. MySQL不香吗,清华架构师告诉你为什么还要有noSQL?

    强烈推荐观看: 阿里P8架构师谈(数据库系列):NoSQL使用场景和选型比较,以及与SQL的区别_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili​www.bilibili.com noSQL的大概 ...

  9. Oracle数据库表被锁死的处理方法

    (1)锁表查询的代码有以下的形式: select count(*) from v$locked_object; select * from v$locked_object; (2)查看哪个表被锁 se ...

  10. Rocket - tilelink - ProbePicker

      简单介绍ProbePicker的实现.   ​​   1. 基本介绍   用于把多个Cache client合并成一个: ​​   2. diplomacy node   ProbePicker的 ...