I'm trying to add string values from a text file to a vector. While doing that, I'm also checking the strings for the number of characters then when reach the word with the desired number of characters, I then add that string into the vector.
But when I'm debugging my program, I keep seeing out of bounds exception and it prints out strings higher than the desired number of characters.
vector<string> words;
vector<string> chosenWords;
ifstream in("WordDatabase.txt");
while(in) {
string word;
in >> word;
cout << word << endl;
//push in selected words based on num of chars
words.push_back(word);
}
for(vector<string>::iterator itr=words.begin(); itr!=words.end();++itr)
{
if((*itr).length() >= 2 || (*itr).length() <= 7)
{
cout << (*itr) << endl;
chosenWords.push_back(*itr);
}
}