I'm trying to print each letter from a data file (will show data).
but my program just ends up printing the while data file without the spaces and not going into the else function.
data.txt:
Write a program that reads several lines from a data file and prints each word of the
file on a separate line of an output file followed by the number of letters in that word.
Also print a count of words in the file on the screen when done. Assume that words are
separated by one or more blanks.
:
so my output is just essentially what is above but with out spaces, when i want it to display each word then go into the else statement where it enters a new line.
As gunnerfunner pointed out you are trying to read each individual character when you need to be working with words.
As the instructions say:
that reads several lines from a data file
That says to me read an entire line until ā\nā is reached then break down the line into individual words. When you break up the line into individual words you can figure out the total number of letters in the word.
Hint variable _name.size() will work. I used a nested while loops and a stringstream to make the program work. I also used a for loop, but that seemed to easy.
You also need a total count of the words in the file and you have no code to output to your output file.