I have a vector of a large text file that I open, and a search words file that I also open. I have two functions, isNextWord which checks if there is another word and the getNextWord which gets the next word.
I check if the search word is in the vector and then print out all the occurences at the end. My code works almost perfectly apart from the fact it skips the last word in the search word file.
For example if my words are: hello,these,are,my,search,words
it will show all occurences apart from "words":
hello 5
these 2
are 5
my 7
search 9
This is my cpp file:
string ReadWords::getNextWord()
{
//gets next word of input from file
return theword;
}
bool ReadWords::isNextWord()
{
return !eoffound;
}
This is my main
while (search.isNextWord()) {
int occ= 0;
string wordFound= search.getNextWord();
for(int i=0; i < vct.size(); i++){
if(vct[i] == wordFound) {
occ++;
}
}
cout << wordSearch << " " << occ<< endl;
}
Why doesn't it perform the getNext word one last time?