A similar program in C++
#include <iostream>
#include <string>
#include <map>
int main() {
std::map<std::string, int> words;
std::string s;
while (std::cin >> s) ++words[s];
std::map<std::string, int>::iterator i;
for (i = words.begin();
i != words.end(); ++i)
std::cout << i->second << ``\t''
<< i->first << std::endl;
}