C ++中的逻辑异或运算符? [英] Logical XOR operator in C++?
本文介绍了C ++中的逻辑异或运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有这样的事吗?这是我第一次遇到实际需要,但我没有看到 Stroustrup 。我打算写:
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 when exactly one of A,B is equal to five.
return (A==5) ^^ (B==5);
但是没有 ^^
运算符。我可以在这里使用bitwise ^
并得到正确的答案(不管机器表示的真和假)?我从不将&
和&&&
或 |
和 ||
,所以我不犹豫地用 ^
和 ^^ / code>。
But there is no ^^
operator. Can I use the bitwise ^
here and get the right answer (regardless of machine representation of true and false)? I never mix &
and &&
, or |
and ||
, so I hesitate to do that with ^
and ^^
.
我会更喜欢写自己的 bool XOR(bool,bool)
>
I'd be more comfortable writing my own bool XOR(bool,bool)
function instead.
推荐答案
!=
运算符用于 bool
值。
这篇关于C ++中的逻辑异或运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文