Or and not equal

前端 未结 6 822
忘掉有多难
忘掉有多难 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:07

    In your second case s != "cm" and of course the first cout is printed. To negate the check and the logic to remain the same, do it like this:

    if((s!="cm")&&(s!="in")&&(s!="ft")&&(s!="m"))
            cout<<"I like "+s;
    else
            cout<

提交回复
热议问题