sosoup85
BAN USERvoid ProcessWordStream() {
std::vector<std::string> wordHolder = {"aca","cat","hello","world"};
std::string inputStream = "acacabcatghhellomvnsdb";
std::map<std::string, int> wordCounter;
int len = inputStream.length();
for(auto word : wordHolder) {
int count = 0;
std::string tempWord = inputStream;
wordCounter[word] = count;
while(tempWord.length() != 0) {
std::size_t pos = tempWord.find(word);
if (pos != std::string::npos) {
wordCounter[word] = ++count;
tempWord = tempWord.substr(pos+word.length()-2);
}
tempWord = tempWord.substr(1);
}
}
for(auto w : wordCounter) {
std::cout << " " << w.first << " : "<<w.second <<"\n";
}
}
- sosoup85 June 25, 2016