Or and not equal

前端 未结 6 684
忘掉有多难
忘掉有多难 2021-01-24 20:23

Why does this work?

#include 
#include 
using namespace std;
int main(){
string s=\"a\";
if((s==\"cm\")||(s==\"in\")||(s==\"ft\")||         


        
6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-24 21:00

    Negation changes the logic behind it. There's more theory here http://en.wikipedia.org/wiki/Negation but basically, in the second example, you want to check that none of the conditions match - meaning you'd have to have && (and) operator instead of || (or)

提交回复
热议问题