How can I find the number of words in a list and..?

Hey guys I have this assignment I'm working on and I need some help with this question. I was given a text document with thousands of words and I have to find the number of words of every possible length and print how many there are in a table. This is what I got so far

1
2
3
4
5
6
7
8
9
10
11
12
13
inStream.open("EnglishWords.txt", ifstream::in);

string word; 
//int number of letters;
//int number of words;

while (inStream) {

    inStream >> word;
    if (word.length() == //Something..)
        //print << number of letters << number of words;

}


So I basically have nothing. Any of you guys able to help me out here? or give me direction of how i should start?
> Give me direction of how I should start?
Just post everything you've got. Yes, everything. Your full code.
@ghoalex

Do you know the size of the largest word in the document? If yes, you can create an array of that size+1; So if the largest word is, let's say, 20 letters long, make an int array like so.
int Word_length[21]. Then, you could have int len = word.length(); as the line 10. After that, Word_length[len]++; to increase the length location of the word i the array. After all is finished, have a for loop from 1 to 21 and cout << "There were " << Word_length[x] << " words of " << x << " length." << endl; ( Assuming that the loop used the x to increase. )

If you don't know the largest size, use maybe 50 instead of 21. In your loop, you could have if(Word_length[x]>0) before printing out how many words had x length.

If this isn't too clear for you, ask for a little more clarification.
what exactly do you need be more specific on the length? every word that has 5 characters in one column. every word with 4 characters in one column? is that what your mean?
closed account (48T7M4Gy)
You need to read the help you've been given in the context that your line 10 is of no use. Read it carefully, write some code and ask questions then.
Are you allowed to use map ?

The easiest would be to use a map<int, int> where key is the length of the word and the value is the number of words with this length.
Topic archived. No new replies allowed.