#include #include #include #include int main () { const char fname[] = "../ex5.3/example.txt"; std::ifstream fh(fname); if ( !fh ) { std::cout << "Error opening (hardcoded) File '" << fname << "'" << std::endl; return 2; } std::map myMap; std::string word; while ( fh >> word ) { myMap[word] += 1; // Lookup the 'word' key and increase its counter; } auto iter = myMap.begin(); while ( iter != myMap.end() ) { std::cout << iter->first << ", " << iter->second << std::endl; iter++; } }