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 //二分查 ...
随机推荐
- Oracle 中同义词使用
一.数据库对象: 模式对象: 数据库对象是逻辑结构的集合,最基本的数据库对象是表; 其他对象包括:create增.drop删.改alter 同义词.序列.视图.索引 1.同义词: ①. 现有对象的一个 ...
- CSS3新子代选择器
:nth-child(n) 选择器匹配属于其父元素的第 N 个子元素,不论元素的类型,除了<h>标签. n 可以是数字.关键词或公式 例子一 <!DOCTYPE html> & ...
- 【JUC】synchronizated和lock的区别&新lock的优势
原始构成 synchronized是关键字,属于JVM层面 javap -c 的结果显示 synchronized是可重入锁 11:是正常退出 17:是异常退出[保证不产生死锁和底层故障] Lock是 ...
- 没找到工作的Java软件工程师是屌丝中的屌丝啊
Java软件开发的工作咋就那么难找呢?
- Bank5
Account: package banking5; //账户 public class Account { protected double balance; public Account(doub ...
- 慕零的黑夜-头条-第一期(必问)[导读:]1.CSDN必问赏金流向何方 2.CSDN必问偷偷做的手脚 3.CSDN必问靠谱吗 4.关于钱于回答的平衡问题:一美元拍卖骗局 作者:qq3461896724
本期是关于CSDN 必问 (biwen.csdn.net)的内容,欢迎评论 文末,文中插入有 小姐姐 img(附py代码,1.49G) + coding资料 哟~~~ 你看到这篇很可能是在提问.推荐加 ...
- 浅谈SIEM
一.概念 SIEM ( Security Information Event Management,安全信息与事件管理) Gartner的定义:安全信息和事件管理(SIEM)技术通过对来自各种事件和上 ...
- 动态ip服务器 动态ip服务器的常用连接方式 收藏版
动态ip服务器目前比较常用的是VPS也叫作虚拟机.目前比较小型的vps服务器与普通电脑没什么区别,最大的区别就是用户连接zhidao服务器内的ip是固定不变的.而服务器运行的ip是可以动态的. 实现动 ...
- 北京理工大学复试上机--2001B
1.请输入高度 h,输入一个高为 h,上底边长为 h的等腰梯形(例如 h=4,图形如下). **** ****** ******** ********** #include <ios ...
- 当微信小程序遇到云开发,再加上一个类似 ColorUI 的模板,人人都能做小程序了
作为一个 Java 程序员,早就想尝试一把微信小程序,但是一直苦于没有想法,再加上做一个漂亮的页面实在不太擅长. 由于自己比较喜欢历史,经常看历史方面的书.在一次梳理中国现有的朝代时,突然想到,要是可 ...