if (user_input == 1)
{
dict.open("dict.txt");
cout << "Enter word ";
cin >> word_check;
toLower(word_check);
vector<string> lines;
string line;
if (dict.is_open()) // if the dictionary is open
{
while (getline(dict,line))
{
lines.push_back(line);
}
if (binarySearch(lines, lines.size(), word_check) != -1)
{
cout << word_check << " is in dictionary" << endl;
}
else
{
cout << word_check << " is not in dictionary" << endl;
}
cout << lines.size() << endl; // testing to see if vector has stored all words
}
}
Okay this is how the program should work:
1. Opens the dictionary file
2. Reads all words (lines) from dictionary file into the vector "lines" and SHOULD store all the words in the vector
3. Uses a binary search to search for specific words STORED IN THE VECTOR and display if found or not..
The problem is.. on the first around, all words are read correctly and the word is able to be found.. but second time around none of the words are read and no words can be found..
Help please, this is really frustrating.
Thanks :)