I'm quite new to C++ and have been solving this uni exercise. (it's actually an assignment, but I haven't been able to finish it on time, but I thought I might try to make it work and learn about C++)..

So, here is part of the description of the program:

It has to read a text file word by word and then separate single letter words from other size words. Other various-sized letters are to be stored and calculate an average word length. But I have already worked out how the other part should work.

PROBLEM IS: single character words can be read in and store into singleWordList by calling the storeWord method. But it wouldn't work for bigWordList, which is using the exact same class as singleWordList.

I'm using two classes:
1. Occurrence for storing word length and occurrence count
2. WordList for storing vector of Occurrence and a vector of string (for storing the word itself)

Here is how I uses the classes in main():

int main()
{
ifstream file("text.txt");
string text;
WordVector bigWordList, singleWordList;

file >> text;

while (!file.eof())
{
if ( text.length() == 1 )
{
singleWordList.storeWord(text);
}
if ( text.length() > 1 )
{
bigWordList.storeWord(text);
cout << "FOUND SOME BIG WORDS" << endl;
}
file >> text;
}


Here is the storeWord method from WordVector class:

/**
* Store the word read in from file into WordList vector and WordCount vector
*/
void WordVector::storeWord(string str)
{
wordList.push_back(str);

/**
* If wordCount vector has an Occourrence object with the same word length,
* increase the occurrence count.
* If not, make a new Occurrence object, set length and occurrenceCount fields,
* then push it onto the wordCount vector.
*/

if ( wordCountList.size() == 0 )
{
newOccr.setLength(str.length());
newOccr.setOccurrenceCount(true);
wordCountList.push_back(newOccr);
}
else
{
for (int i=0; i< wordCountList.size() ; i++)
{
if (wordCountList[i].getLength() == str.length())
{
wordCountList[i].setOccurrenceCount(true);
}
else
{
newOccr.setLength(str.length());
newOccr.setOccurrenceCount(true);
wordCountList.push_back(newOccr);
}
}
}
}


My text file contains: A is the first word of English alphabet. Z is the last.

And the output is:

FOUND SOME BIG WORDS
FOUND SOME BIG WORDS
FOUND SOME BIG WORDS
FOUND SOME BIG WORDS
FOUND SOME BIG WORDS
FOUND SOME BIG WORDS
FOUND SOME BIG WORDS
FOUND SOME BIG WORDS
FOUND SOME BIG WORDS
SINGLE WORDS
-------------
A
Z
BIG WORDS
-----------
bigWordList size is: 0Press any key to continue

Is the error something to do with push_back method called on the vector?

I appreciate all your help and advice. Thanks in advance.
Kenn