C++ count() the number of objects with a specified value

Description

C++ count() 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()/*from w  ww .  j  a  v  a2 s.  co  m*/
{
   int n = count(arr, arr+8, 33);  //count number of 33's
   cout << "There are " << n << " 33's in arr." << endl;
   return 0;
}



PreviousNext

Related