1// count algorithm example
2#include <iostream> // std::cout
3#include <algorithm> // std::count
4#include <vector> // std::vector
5
6int main () {
7 // counting elements in array:
8 int myints[] = {10,20,30,30,20,10,10,20}; // 8 elements
9 int mycount = std::count (myints, myints+8, 10);
10 std::cout << "10 appears " << mycount << " times.\n";
11
12 // counting elements in container:
13 std::vector<int> myvector (myints, myints+8);
14 mycount = std::count (myvector.begin(), myvector.end(), 20);
15 std::cout << "20 appears " << mycount << " times.\n";
16
17 return 0;
18}