c++之STL(13) STL 算法 - 查找算法(4)find_first_of(b,e,sb,se) find_first_of(b,e,sb,se,bp)
2016-08-08 22:28
381 查看
find_first_of(b,e,sb,se)
find_first_of(b,e,sb,se,bp)
使用逆向迭代器 没有find_last_of算法
STL 查找算法
find()
find_if()
search_n()
search()
find_end()
find_first_of()
adjacent_find()
string 查找函数和STL查找算法的比较
string函数 STL算法
find() find()
rfind() find() + 逆向迭代器
find() search()
rfind() find_end()
find_first_of() find_first_of()
find_last_of() find_first_of() + 逆向迭代器
find() 和rfind()是一对,search()和find_end()是一对
#include<iostream>
#include<vector>
#include<list>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
vector<int> ivec;
list<int> searchList;
for (int i = 1; i <= 11; i++)
ivec.push_back(i);
for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); iter++)
{
cout << *iter;
}
cout << endl;
searchList.push_back(3);
searchList.push_back(6);
searchList.push_back(9);
// 找任意一个
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) + 1 << endl;
}
else
cout << "没找到!";
//从后面找
vector<int>::reverse_iterator rpos;
rpos = find_first_of(ivec.rbegin(), ivec.rend(), searchList.begin(), searchList.end());
cout << "找到的位置:" << distance(ivec.begin(), rpos.base()) << endl;
//
string numerics("0123456789");
string name("ra8d3k");
// 找任何一个
string::size_type p = name.find_first_of(numerics);
if (p != string::npos)
cout << "找到了,下标:" << p << endl;
else
cout << "没找到!" << endl;
//从后面开始找
p = name.find_last_of(numerics);
if (p != string::npos)
cout << "找到了,下标:" << p << endl;
else
cout << "没找到!" << endl;
//
system("pause");
return 0;
}
find_first_of(b,e,sb,se,bp)
使用逆向迭代器 没有find_last_of算法
STL 查找算法
find()
find_if()
search_n()
search()
find_end()
find_first_of()
adjacent_find()
string 查找函数和STL查找算法的比较
string函数 STL算法
find() find()
rfind() find() + 逆向迭代器
find() search()
rfind() find_end()
find_first_of() find_first_of()
find_last_of() find_first_of() + 逆向迭代器
find() 和rfind()是一对,search()和find_end()是一对
#include<iostream>
#include<vector>
#include<list>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
vector<int> ivec;
list<int> searchList;
for (int i = 1; i <= 11; i++)
ivec.push_back(i);
for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); iter++)
{
cout << *iter;
}
cout << endl;
searchList.push_back(3);
searchList.push_back(6);
searchList.push_back(9);
// 找任意一个
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) + 1 << endl;
}
else
cout << "没找到!";
//从后面找
vector<int>::reverse_iterator rpos;
rpos = find_first_of(ivec.rbegin(), ivec.rend(), searchList.begin(), searchList.end());
cout << "找到的位置:" << distance(ivec.begin(), rpos.base()) << endl;
//
string numerics("0123456789");
string name("ra8d3k");
// 找任何一个
string::size_type p = name.find_first_of(numerics);
if (p != string::npos)
cout << "找到了,下标:" << p << endl;
else
cout << "没找到!" << endl;
//从后面开始找
p = name.find_last_of(numerics);
if (p != string::npos)
cout << "找到了,下标:" << p << endl;
else
cout << "没找到!" << endl;
//
system("pause");
return 0;
}
相关文章推荐
- C++ STL 算法:查找算法(4)find_first_of
- c++之STL(13) STL 算法 - 查找算法(6)binary_search(b,e,v) binary_search(b,e,v,p) includes(b,e,sb,se) include
- c++之STL(13) STL 算法 - 查找算法(5)adjacent_find(b,e) adjacent_find(b,e,p)
- STL_算法_查找算法(find_first_of、find_last_of)
- c++之STL(13) STL 算法 - 查找算法(3)search() find_end()
- 实战c++中的vector系列--vector应用之STL的find、find_if、find_end、find_first_of、find_if_not(C++11)
- c++之STL(13) STL 算法 - 查找算法(7)lower_bound() upper_bound() equal_range(0
- C++STL库中string类的find()和findfirstof()函数比较
- C++语法基础--泛型算法(generic algorithm)--只读算法accumulate(),find_first_of(),count(),count_if()
- C++ STL 算法:查找算法(5) vadjacent_find
- 实战c++中的vector系列--vector应用之STL的find、find_if、find_end、find_first_of、find_if_not(C++11)
- c++之STL(13) STL 算法 - 查找算法(1)
- c++之STL(13) STL 算法 - 查找算法(2)search_n() search_n(b, e, c, v) search_n(b, e, c, v, p)
- C++的STL之find_first_of
- C++ 11.2 accumulate、find_first_of 函数
- C++ STL 算法:查找算法(2) search_n
- C++基础---string类的find/find_first_of/find_first_not_of/rfind/find_last_of/find_last_not_of
- STL 之find,find_if,find_end,find_first_of
- 查找算法---find运算,find_first_of的使用
- STL_算法_查找算法(find、find_if)