小编Ale*_*der的帖子

我如何解决这个奇怪的 while 循环错误?

我有一个 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)

为什么它打印出与响应相同数量的单词的“查询”?

c++ while-loop

2
推荐指数
1
解决办法
84
查看次数

标签 统计

c++ ×1

while-loop ×1