//#include <map>
//#include <iostream>
int main() {
std::map<int, unsignedint> numberCount;
int x;
while (std::cin >> x ) {
++numberCount[x];
}
std::cout << "x\tcount\n";
// OK. I see how a range based for loop would be nice here. I should update my compiler.
for ( std::map<int, unsignedint>::const_iterator it = numberCount.begin(); it != numberCount.end(); ++it )
std::cout << it->first << '\t' << it->second << '\n';
return 0;
}
The code is adapted from this post in another thread:
http://www.cplusplus.com/forum/beginner/132369/#msg712641