标签:元素 position == main UNC span end ret pac
#include <iostream> // cout #include <algorithm> // find_end #include <vector> // vector using namespace std; bool myfunction (int i, int j) { return (i==j); } int main () { int myints[] = {1,2,3,4,5,1,2,3,4,5}; vector<int> haystack (myints,myints+10); int needle1[] = {1,2,3}; // using default comparison: vector<int>::iterator it; it = find_end (haystack.begin(), haystack.end(), needle1, needle1+3); if (it!=haystack.end()) cout << "needle1 last found at position " << (it-haystack.begin()) << ‘\n‘; int needle2[] = {4,5,1}; // using predicate comparison: it = find_end (haystack.begin(), haystack.end(), needle2, needle2+3, myfunction); if (it!=haystack.end()) cout << "needle2 last found at position " << (it-haystack.begin()) << ‘\n‘;return 0; }
C++ 在容器A中查找容器B中的元素,并返回iterator(find_end)
标签:元素 position == main UNC span end ret pac
原文地址:https://www.cnblogs.com/sea-stream/p/9823550.html