Counting Instances of a Value in a Sequence Using the count algorithm - C++ STL Algorithm

C++ examples for STL Algorithm:count

Description

Counting Instances of a Value in a Sequence Using the count algorithm

Demo Code

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
    vector<int> myVector{ 3, 2, 3, 7, 3, 8, 9, 3 };
    auto number = count(myVector.begin(), myVector.end(), 3);
    cout << "The number of 3s in myVector is: " << number << endl;

    return 0;/*from www  .ja va  2 s.com*/
}

Result


Related Tutorials