Or and not equal

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

    Why should the second one output "I like a"? Every single one of your conditions in the statement in the second example is true, so it goes into the if branch. Even if only one would be true, it still would go into the if branch, because you are using OR.

提交回复
热议问题