Mauro Baraldi
0
Q:

count vector c++

auto element = 5; // search for 5 in vector vect
auto element_count = count(vect.begin(), vect.end(), element);
0
// C++ program for count in C++ STL for 
// array 
#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
    int arr[] = { 3, 2, 1, 3, 3, 5, 3 }; 
    int n = sizeof(arr) / sizeof(arr[0]); 
    cout << "Number of times 3 appears : "
         << count(arr, arr + n, 3); 
  
    return 0; 
} 
0

New to Communities?

Join the community