My task is that I don't know number of words in a file and the words are repeating several times,but how many times - It's unknown and I have to find that words. I use classes and vector to work with words,and fstream to work with files. But I cannot find resource or algorithm of finding repeating words and I'm so puzzled. I have vector of variable type and I pushed the words in it. It works successfully,I test it with v.size() output. I made all of things except algorithm of finding repeating words,which solve turned difficult to me.
My full code that I wrote:
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iterator>
using namespace std;
class Wording {
private:
string word;
vector <string> v;
public:
Wording(string Alternateword, vector <string> Alternatev) {
v = Alternatev;
word = Alternateword;
}
};
int main() {
ifstream ifs("words.txt");
ofstream ofs("wordresults.txt");
string word;
vector <string> v;
Wording obj(word,v);
while(ifs >> word) v.push_back(word);
for(int i=0; i<v.size(); i++) {
//waiting for algorithm
//ofs << v[i] << endl;
}
return 0;
}