0

I am currently working on a program that reads the contents from a file and then puts these contents into a trie. The contents of the file are all of words in the English Language. The problem I am having is that it appears that my code is getting stuck in my while loop, I know the words are getting inserted due to my insert function returning 1 or true. So I don't why my code is getting stuck in my while loop. Any help would be amazing.

I have already tried saying if the string words is more than the buffer than stop, I have tried using getline as my loop condition, by none of those solutions seem to work.

Below is my code:

Trie t1 = Trie();
string words;
fstream myfile;
myfile.open("wordlist.txt");
while(!myfile.eof()){
    getline(myfile, words, ' ');
    t1.insert(words);
}
myfile.close();
m.raynal
  • 2,983
  • 2
  • 21
  • 34
Linkle
  • 1
  • Possible duplicate of [Why is iostream::eof inside a loop condition considered wrong?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong) – Mike Borkland Apr 01 '19 at 23:28
  • Use `getline` as the guard to your `while` loop. – Mike Borkland Apr 01 '19 at 23:30

0 Answers0