小编lil*_*ton的帖子

为什么str!=“ hello” &&“再见”不起作用?

如果输入字符串“ hello”或“再见”我试图退出“ do”功能,此功能仅适用于“ hello”而不是“再见”。谁能向我解释我的功能有什么问题?另外,如果有更好的方法,我也希望看到。谢谢

“你好” || “再见”“你好”,“再见”

#include <iostream>
#include <string>



int main()
{
    std::string str;
    do {

        std::cout << "Say Hello, sir.";
        std::cin >> str;

    } while (str != "Hello" && "Goodbye");

    std::cout << "You're rude, bro";
}
Run Code Online (Sandbox Code Playgroud)

我希望在输入“ Hello”或“ Goodbye”之后退出“ do”语句并继续执行cout语句。

c++ string function

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

标签 统计

c++ ×1

function ×1

string ×1