The program that can be listed below helps you to learn the count() function in the C++ language :
Code:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int mcnt;
int mnts[] = {10,20,30,30,20,10,10,20};
mcnt = (int) count (mnts, mnts+8, 10);
cout << "10 appears " << mcnt << " times.\n";
vector<int> mvctr (mnts, mnts+8);
mcnt = (int) count (mvctr.begin(), mvctr.end(), 20);
cout << "20 appears " << mcnt << " times.\n";
return 0;
}
The output of the above program :
Code:
10 appears 3 times.
20 appears 3 times.
Bookmarks