Really need help on finding length in text file.

1. Find the largest word on the list, print it, and print it's length (the str.length() function will help here!).

2. Find all of the words with one letter and print them.

3. Find the number of words of every possible length and print how many there are in a table.
The table should start off looking like this:

Length Number of Words
1 2
2 140
. .
. .
. .

What is the commonest length of English word?

this is what instructor give for the lab with the text file have all vocabs of english. and answer the questions above. I dont really know how to start it, can someone help ? Thanks
Well, reading the text file isn't too hard. The issue is parsing- you know the words will be split by spaces. So what you could do is have an integer of last_delimiter. Set it to -1 at first. The put the whole thing in a giant for loop, with the main index parsing the input string (which, in itself, is probably in a giant for loop for reading the file input). From there, it is rather straightforward- once the main index character is a space, put everything from last_delimiter to index into a string, and stick it into a vector. Set last_delimiter to index, and begin again.

After that, you should have a vector of every word. Deal with that as you wish.
Well, thanks but the way you do is completely different then what I have learned, and I dont know what is vector as last_delimiter, can u tell specific or different way please ? thanks !
I also know how to open file but idk how to read . :(
Topic archived. No new replies allowed.