//: C06:Counting.cpp // From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison. // (c) 1995-2004 MindView, Inc. All Rights Reserved. // See source code use permissions stated in the file 'License.txt', // distributed with the code package available at www.MindView.net. // The counting algorithms. //{L} Generators #include #include #include #include #include #include "Generators.h" #include "PrintSequence.h" using namespace std; int main() { vector v; generate_n(back_inserter(v), 50, CharGen()); print(v.begin(), v.end(), "v", ""); // Create a set of the characters in v: set cs(v.begin(), v.end()); typedef set::iterator sci; for(sci it = cs.begin(); it != cs.end(); it++) { int n = count(v.begin(), v.end(), *it); cout << *it << ": " << n << ", "; } int lc = count_if(v.begin(), v.end(), bind2nd(greater(), 'a')); cout << "\nLowercase letters: " << lc << endl; sort(v.begin(), v.end()); print(v.begin(), v.end(), "sorted", ""); } ///:~