#include #include #include #include #include // for exit using namespace std; ostream& operator <<(ostream& out,const pair& p) { out << p.second << "\t" << p.first; return out; } int main(int argc, char *argv[]) { string filename,w; if (argc == 1) { cerr << "usage: " << argv[0] << " filename" << endl; exit(1); } filename = argv[1]; ifstream input(filename.c_str()); map m; while (input >> w) { map::iterator it = m.find(w); if (it == m.end()) { m.insert(make_pair(w,1)); } else { it->second++; } } copy(m.begin(),m.end(), ostream_iterator >(cout,"\n")); return 0; }