1
0
Fork 0
This repository has been archived on 2021-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
uni-m.cds-adv-prog/ex7.1/main.cpp

32 lines
568 B
C++

#include <fstream>
#include <iostream>
#include <string>
#include <map>
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<std::string,int> 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++;
}
}