爲什麼我不能得到正確的字符串。我在表達中有什麼錯誤?我無法弄清楚。我儲存了好幾個小時。爲什麼我的或操作員不工作?
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
using namespace std;
int main(){
string var = "y";
string constant ="y";
if ((var != constant)||(var != "n")){
cout << "error";
}
else {
cout << "right" // this is what it should print
}
}
我明白,或運營商使用||作爲符號。那麼爲什麼我的程序不能執行它的任務
預期結果是什麼?根據「if」條件,代碼將打印出「錯誤」。 – songyuanyao
'var!=「n」'是真的,所以整個表達式都是真實的。 – dasblinkenlight
'var'不能同時等於兩個不同的東西... – Dmitri