我在使用c ++中的if语句和字符串/字符时遇到了一些麻烦.这是我的代码:
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "-----------------------------" << endl;
cout << "|Welcome to Castle Clashers!|" << endl;
cout << "-----------------------------" << endl;
cout << "Would you like to start?" << endl;
string input;
cout << "A. Yes ";
cout << "B. No " << endl;
cin >> input;
if(input == "a" || "A"){
cout << "Yes" << endl;
}else{
if(input == 'b' || 'B'){
return 0;
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在我的if语句中,它检查字符串输入是否等于yes,如果不是,则应该转到else语句.这是麻烦开始的地方,一旦我在控制台中运行我的程序,当我输入"a"或"A"之外的任何东西时,它仍然会说是.我尝试用字符/字符做,但我得到相同的输出.有人可以帮助我吗?
c++ ×1