c ++如果来自字符串的特定单词

c++ if specific words from string

我想检查定义字符串 (cin) 中几个单词的 if 语句,以便它接受大写和小写首字母的不同使用。

#include <iostream>
using namespace std;

int main()
{
string BothMods;

cout << "Are both online?" << endl;
cin >> BothMods;

if (BothMods == "Yes", "YES", "yes"{
    cout <<"Both are online" << endl; 

...

但是当我输入三个条件之一时,条件始终为假(否则执行)。如果我只使用一个(比如 if (BothMods == "Yes") )它就可以工作。

如果要检查多个案例,则需要使用 OR 运算符单独检查每个案例。

if (BothMods == "Yes" || BothMods == "YES" || BothMods == "yes") {
    // do whatever
}