Logical XOR operator in C++?

后端 未结 11 1281
轮回少年
轮回少年 2020-11-29 15:54

Is there such a thing? It is the first time I encountered a practical need for it, but I don\'t see one listed in Stroustrup. I intend to write:

// Detect wh         


        
11条回答
  •  被撕碎了的回忆
    2020-11-29 15:57

    For a true logical XOR operation, this will work:

    if(!A != !B) {
        // code here
    }
    

    Note the ! are there to convert the values to booleans and negate them, so that two unequal positive integers (each a true) would evaluate to false.

提交回复
热议问题