find()、find_end()、find_first_of()、find_if()的使用示例和区别
2009-05-28 02:08
525 查看
http://blog.csdn.net/xqls_xqls/archive/2008/12/03/3437640.aspx
#include <vector> #include <iostream> #include <algorithm> #include <functional> #include <string> using namespace std; int main(int argc,_TCHAR* argv[]) { //find_first_of()的使用 int nums1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int* result1; int start = 0; int end = 10; int targets[] = { 9, 11, 7 }; result1 = find_first_of( nums1 + start, nums1 + end, targets + 0, targets + 2 ); if( *result1 == nums1[end] ) cout << "Did not find any of { 9, 11, 7 }" << endl; else cout << "Found a matching target: " << *result1 << endl; //find_end()的使用 int nums[] = { 11, 2, 3, 4, 1, 2, 3, 4, 11, 2, 3, 4 }; int* result; end = 11; int target1[] = { 1, 2, 3 }; result = find_end( nums + start, nums + end, target1 + 0, target1 + 2 ); if( *result == nums[end] ) cout << "Did not find any subsequence matching { 1, 2, 3 }" << endl; else cout << "The last matching subsequence is at: " << *result << endl; int target2[] = { 3, 2, 3 }; result = find_end( nums + start, nums + end, target2 + 0, target2 + 2 ); if( *result == nums[end] ) cout << "Did not find any subsequence matching { 3, 2, 3 }" << endl; else cout << "The last matching subsequence is at: " << *result << endl; //find()的使用 int num_to_find = 3; vector<int> v1; for( int i = 0; i < 10; i++ ) v1.push_back(i); vector<int>::iterator result2; result2 = find( v1.begin(), v1.end(), num_to_find ); if( result2 == v1.end() ) cout << "Did not find any element matching " << num_to_find << endl; else cout << "Found a matching element: " << *result2 << endl; //find_if()的使用 int nums3[] = { 0, -1, -2, -3, -4, 342, -5 }; start = 0; end = 7; result = find_if( nums3 + start, nums3 + end, bind2nd(greater<int>(), 0)); if( *result == nums3[end] ) cout << "Did not find any number greater than zero" << endl; else cout << "Found a positive non-zero number: " << *result << endl; return 0; }
相关文章推荐
- C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用
- C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用
- 非变异算法之查询( find(), find_if(), find_first_of, adjacent_find(), find_end(), search(), search_n() )
- find ,find_first_of , find_if , adjacent_find的使用
- C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用
- 实战c++中的vector系列--vector应用之STL的find、find_if、find_end、find_first_of、find_if_not(C++11)
- C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用
- STL 之find,find_if,find_end,find_first_of
- 实战c++中的vector系列--vector应用之STL的find、find_if、find_end、find_first_of、find_if_not(C++11)
- C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用
- C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用
- C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用
- C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用
- STL 之find,find_if,find_end,find_first_of
- 关于 find_first_of(beg1, end1, beg2, end2, op)
- string类中find() 函数 和find_first_of()函数的区别
- (原創) 如何使用find_first_of() algorithm? (C/C++) (STL)
- 非变动性算法源代码分析与使用示例( for_each、min_element 、find_if、search 等)
- 查找算法---find运算,find_first_of的使用
- STL(五):非变动性算法源代码分析与使用示例( for_each、min_element 、find_if、search 等)