I'm taking in a text file and putting the words into a vector. If the vector already contains the word, it will increment the occurance memeber. If it's a new word, we push it onto the vector. When I debug this, everything seems correct, but the vector is filled with every single word, with occurance = 1 because "i" seems to be one index behind.
If I initialize with i=1 though, the the vector will go out of range. Any help?
vector<wordFreq> words;
//already have 1 in vector, i initialized at 0.
while(!myfile.eof())
{
myfile >> tempWord; //takes word into variable
if (words[i].wordName == tempWord) //if it is found
{
//words[i].occurances++; //increment occurance member
}
else
{
//create new object
wordFreq tempElement;
tempElement.occurances = 1;
tempElement.wordName = tempWord;
words.push_back (tempElement); //push onto vector
}
i++;
}