我有一个 while 循环,它询问用户的查询并接受响应,可以是一个词,也可以是一个句子。输出让我难以置信。
std::string response;
while (response != "!quit")
{
cout << "Query? ";
cin >> response;
if (response == "!quit")
{
cout << "Thank you for using this program!";
exit(0);
}
}
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
Query? how are you
Query? Query? Query? how are you today
Query? Query? Query? Query? hi
Query?
Run Code Online (Sandbox Code Playgroud)
为什么它打印出与响应相同数量的单词的“查询”?