I have a while loop that asks the user's query and takes in a response, could be a word, could be a sentence. The output is boggling me.
std::string response;
while (response != "!quit")
{
cout << "Query? ";
cin >> response;
if (response == "!quit")
{
cout << "Thank you for using this program!";
exit(0);
}
}
The output for this looks like this:
Query? how are you
Query? Query? Query? how are you today
Query? Query? Query? Query? hi
Query?
why is it printing out "query" for the same number of words as the response?
response
defined? – DarkAtom Oct 30 '20 at 20:44std::string
? – πάντα ῥεῖ Oct 30 '20 at 20:54response
variable. When the loop seems to be misbehaving, take a look at the value of that variable (e.g.cout << "response is '" << response <<"'.\n";
right after you read it fromcin
). – JaMiT Oct 30 '20 at 21:33