0

I want to ask the user if they want to continue playing another round or quit. If they want to continue I expect them to enter two words in getline, but if they enter quit, I want to break;. Is this possible?

Can I check to see if the first letter is a "q" and then use putback if it is not? Or can I check the whole word and putback if it is not quit (I would not know the length of the word). Id there some other way I can approach this?

Thank you!

user3027672
  • 11
  • 1
  • 3
  • This might be easier to answer if you post some code. Are you actually using `getline`? And then checking the input one letter at a time? – doctorlove Dec 02 '13 at 17:29
  • You can't put back anything more than a single character. Can't see why reading a whole line, checking if it's "quit" and then carrying on processing if it is not, doesn't work. Agree that (as always) some code helps to clarify things. – john Dec 02 '13 at 17:30

1 Answers1

0

Yes.

I recommend using getline to read each line of user input. Then parse the string in order to determine what action to take. I don't see how a putback would be useful if it were possible. If necessary you can use a stringstream to get numeric info out of the string, or you can simply compare characters. It is up to you to determine the approach but there are a variety of ways in which you could design the program.

Take a look at this. Try to avoid the common gotchas associated with standard streams otherwise you will soon be googling for answers to other questions. http://www.parashift.com/c++-faq/input-output.html

shawn1874
  • 1,288
  • 1
  • 10
  • 26