Hi. I've written a program for a beginner C++ class that asks the user to enter a generic five-word phrase (with a single space between). It then outputs each word of the phrase separately. The program runs fine and doesn't terminate or skip words if the user accidentally enters a double space. But my instructions say to use various string manipulation functions. How do I add those to my program? Here is the program:
, but I'm going about it all wrong. I still don't know how to split the words and get them to output separately. I know it has something to do with where the cursor is and how it reads spaces, but don't know how to write it. Also, I don't know what the cout statement would be.
The getline() function reads a line, not just a word. So by saying getline so many times you just put your program to read more lines... So you just need one getline() that will store all the words in a single string.
Hint: you will need two indices into the string: where the next word starts and where it ends
When you have a phrase, like "This is a phrase", what is the key to separate each word? It is like reading it.