template <class InputIterator, class Predicate> bool any_of( InputIterator qFirst, InputIterator qLast, Predicate qTester );
#include <algorithm>
#include <iostream> #include <vector> #include <algorithm> bool HasAnA(char cChar) { return (cChar == 'a'); } int main() { using namespace std; // Create two vector instances vector<char> qV; qV.push_back('X'); qV.push_back('o'); qV.push_back('a'); qV.push_back('X'); qV.push_back('.'); qV.push_back('n'); qV.push_back('e'); qV.push_back('t'); // Test all entries of the vector bool bAnyIsA = any_of(qV.begin(), qV.end(), HasAnA); cout << (bAnyIsA ? "An" : "No") << " entry is \'a\'" << endl; vector<char>::iterator qIter = qV.begin(); ++qIter; // Test the first entry of the vector bAnyIsA = any_of(qV.begin(), qIter, HasAnA); cout << (bAnyIsA ? "An" : "No") << " entry is \'a\'" << endl; cin.get(); return 0; }
© 20072024 XoaX.net LLC. All rights reserved.