Counts the number of objects with a specified value - C++ STL Algorithm

C++ examples for STL Algorithm:count

Description

Counts the number of objects with a specified value

Demo Code

#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;
}

Result


Related Tutorials