C++ examples for STL Algorithm:count
Counts the number of objects with a specified value
#include <iostream> #include <algorithm> //for count() using namespace std; int arr[] = { 33, 22, 33, 44, 33, 55, 66, 77 }; int main()/* w ww . j a v a2 s. c om*/ { int n = count(arr, arr+8, 33); //count number of 33's cout << "There are " << n << " 33's in arr." << endl; return 0; }