Word Frequencies
#include <sstream>
#include <fstream>
#include <algorithm>
using namespace std;
// command line: process each arguement in the arguement_vector[0 - > arguement count]
int main(int arguement_count, char **arguement_vector)
{
unordered_map<string, int> myMap;
ifstream file(arguement_vector[1]);
string word;
while (file >> word) {
// if I want lower case words: <algorithm>
transform(word.begin(), word.end(), word.begin(), ::tolower);
auto find = myMap.find(word);
// not found
if (find == myMap.end()) {
myMap.insert({ { word }, { 1 } });
}
// found
else {
myMap.find(word)->second++;
}
}
}Last updated