cb31a_c++_STL_算法_查找算法_(4)find_first_of
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的更多相关文章
- cb34a_c++_STL_算法_查找算法_(7)_lower_bound
cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置uppe ...
- cb33a_c++_STL_算法_查找算法_(6)binary_search_includes
cb33a_c++_STL_算法_查找算法_(6)binary_search_includes//针对已序区间的查找算法,如set,multiset关联容器-自动排序binary_search(b,e ...
- 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 ...
- cb30a_c++_STL_算法_查找算法_(3)search_find_end
cb30a_c++_STL_算法_查找算法_(3)search_find_endsearch()pos = search(ideq.begin(), ideq.end(), ilist.begin() ...
- 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 ...
- cb28a_c++_STL_算法_查找算法_(1)find_find_if
cb28a_c++_STL_算法_查找算法_(1)find_find_iffind() //线性查找,比较慢.pos1 = find(ilist.begin(), ilist.end(), 5);fi ...
- STL_算法_查找算法(lower_bound、upper_bound、equal_range)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n))) 已序区间查找算法 lower_bound() //找第一个符合的 ...
- STL_算法_查找算法(find、find_if)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...
- STL_算法_查找算法(binary_search、includes)
C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n))) 已序区间查找算法 binary_search //二分查 ...
随机推荐
- 【原创】CentOS 7搭建多实例MySQL8(想要几个搞几个)
起因 最近项目上开始重构,可能会用到主从加读写分离的情况,就想先在本地搭一个出来试试效果,结果百度一搜出来一大堆,然而自己去踩坑的没几个,绝大多数都是去抄的别人的内容,关键是实际应用中还会出错,浏览器 ...
- NOIP 2017 P3959 宝藏 (状态压缩DP板子)
洛谷题目传送门!! 题目的N这么小,当然是选择用状压DP啦! 等等,我好像不会状缩.... 首先,我们当然是要写状态转移方程了!! 那么,如果我们设 f[s] 状态s下,所要的最小花费,那么很显 ...
- html5学习之路_001
安装环境 安装intellij idea作为开发环境 打开环境 新建一个html文件,打开之后出现代码框架,再次基础上继续编码即可,例如: <!DOCTYPE html> <html ...
- matlab自学笔记
1.字符串格式化,用sprintf如a=sprintf('%.2f_除以%d等于%.3f',1.5,2,0.75)%则a=1.50除以2等于0.750 2.for循环只能针对整数,不能遍历字符串或其他 ...
- RxJS 中的创建操作符
RxJs 中创建操作符是创建数据流的起点,这些操作符可以凭空创建一个流或者是根据其它数据形式创建一个流. Observable的构造函数可以直接创建一个数据流,比如: const $source=ne ...
- 错误记录:Data too long for column 'xxx' at row 1
错误记录:Data too long for column 'xxx' at row 1 使用Flask-sqlalchemy操作数据时报错: "Data too long for colu ...
- 循序渐进VUE+Element 前端应用开发(6)--- 常规Element 界面组件的使用
在我们开发BS页面的时候,往往需要了解常规界面组件的使用,小到最普通的单文本输入框.多文本框.下拉列表,以及按钮.图片展示.弹出对话框.表单处理.条码二维码等等,本篇随笔基于普通表格业务的展示录入的场 ...
- ie时间格式NAN-NAN-NAN
js的日期对象可以识别的日期字符串有四种: 1.YYYY-MM-DD 2019-11-11 01:01:012.MM-DD-YYYY 11-11-2019 01:01:013.YYYY/MM/DD 2 ...
- 拨开云雾-Verilog是个大杂烩(中性)
https://mp.weixin.qq.com/s/HKxX_79DtnXmFU1Mwt1GwA 一. 有意为之 Verilog是个大杂烩,这是有意而为之. Verilog IEEE S ...
- 【Mybatis plus 3.2】怎么操作?看看我!(update、limit、between)
必须是springboot工程 在pom.xml中添加 <dependency> <groupId>com.baomidou</groupId> <artif ...