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