I am trying to have an input statement inside a loop
to input a string and when it sees a period in the end it breaks
and display the string in reversed order.
this is my question " input statement inside a loop
to input a string and when it sees a period in the end it breaks
and display the string in reversed order. "
I am having difficulty in writing a loop that can input bunch strings and when it sees a period it exits the loop and display the whole strings backwards. Is the question clear now?
the examples you suggested won't work since my code is not correct!
Printing in reverse is an entirely separate task. Think, why you do use a stack for storing the words.
I now see that my code cannot properly do the necessary logic. What I had in mind would have discarded the last word. Again:
1 2 3 4 5 6 7
while ( cin >> word ) {
// there are now four possibilities:
// * word is empty -- skip it
// * word is just a word -- store it
// * word ends with a dot -- store and break
// * word is a dot -- (store? and) break
}
I did give you the link to std::string::back() for a purpose.