Or login with:
#include <algorithm> template < class InputIterator, class Type> typename iterator_traits<InputIterator>::difference_type count( InputIterator first, InputIterator last, const Type& val );Parameters:
| Parameter | Description |
|---|---|
| first | An input iterator addressing the position of the first element in the range to be traversed |
| last | An input iterator addressing the position one past the final element in the range to be traversed |
| val | The value of the elements to be counted |
i in [first, last) such that *i == value.last - first comparisons.
#include <vector> #include <algorithm> #include <iostream> using namespace std; 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 result; result = count(v1.begin(), v1.end(), 10); cout <<"The number of 10s in v2 is: "<<result<<"."<<endl; return 0; }
You must login to leave a messge