Or login with:
#include <algorithm> template < class InputIterator, class Predicate > typename iterator_traits<InputIterator>::difference_type count_if( InputIterator first, InputIterator last, Predicate pred );Parameters:
| Parameter | Description |
|---|---|
| first | An input iterator addressing the position of the first element in the range to be searched |
| last | An input iterator addressing the position one past the final element in the range to be searched |
| pred | User-defined predicate function object that defines the condition to be satisfied if an element is to be counted. A predicate takes single argument and returns true or false |
operator==.#include <vector> #include <algorithm> #include <iostream> using namespace std; bool greater10(int value) { return value >10; } int main() { vector<int> v1; vector<int>::iterator Iter; v1.push_back(10); v1.push_back(20); v1.push_back(10); v1.push_back(40); v1.push_back(10); cout <<"v1 = ( "; for (Iter = v1.begin(); Iter != v1.end(); Iter++) cout <<*Iter<<" "; cout <<")"<< endl; vector<int>::iterator::difference_type result1; result1 = count_if(v1.begin(), v1.end(), greater10); cout <<"The number of elements in v1 greater than 10 is: " <<result1<<"."<<endl; return 0; }
You must login to leave a messge