为什么我不能得到正确的字符串。我在表达中有什么错误?我无法弄清楚。我储存了好几个小时。为什么我的或操作员不工作?
#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