1 Attachment(s)
How do I clear ifstream!?
I am trying to write a simple spell checking program but no matter what I do it will only read through the word list once and all other times it just thinks it is the end of the file and does a check for the first word I put in...
Here is the code:
Code:
while (repeat==true) {
word_list.clear();
word_list.seekg(0, ios::beg);
cout << "\n\nType word here (lowercase): ";
cin >> input;
system("clear");
while (!word_list.eof()) {
word_list >> read;
cout << "\nTrying: " << read;
if (read==input) {
system("clear");
cout << " is a word!\n\n";
repeat=true;
//word_list.close();
word_list.clear();
word_list.seekg(0, ios::beg);
break;
}
else{
check0=1;
}
}
if (read!=input) {
system("clear");
//word_list.close();
word_list.clear();
word_list.seekg(0, ios::beg);
cout << "\n\n" << input << " is not a word!\n\n";
}
}
EDIT: Resolved: removing word_list.close() fixed the issue
I attached the full cpp file for reference...