Keskiverto explained it well, I can't explain it near as good but it may help to hear it from more than one source.
This is the possible approach you could take,
1) Read in from a text file, instead of using the << operator it may be more efficient to read in full lines so use getline([stream],[string]) , store the result in a temporary string - hint use a while loop
|
while(getline(input,line)){}
|
2) Now you can break this line into individual words using a stringstream
http://www.cplusplus.com/reference/sstream/stringstream/stringstream/
3) You will need a container to store your words in, use a vector.
4) Populate the vector WHILE strings are present in the stringstream, hint use an inner while loop
5) Now that we have broken our line into words, loop through the words if and ONLY if the vector of words is greater than 0 ( if it's 0 this is an empty line, possibly spacing from a paragraph ) ,create an integer named count outside the main while loop called letter count.
6) Add the size of each word to the variable count.
1 2 3
|
count += words.at(0).size();
|
note you will also need to check if the last letter in a word is punctuation, if so you will not count this.
7) Clear the stringstring for the next line.
1 2 3 4
|
ss.str("");
ss.clear();
|
8) Print the number of letters.
If you have any further questions , please do I ask hopefully I can help and hopefully this was of some help.