什么是 C++对于“AND OR”?
我正在写一些条件 if 并且我想要类似
if ( /*condition one */) and or ( /* condition two */ )
C++ 中是否有这样的运算符以及如何编写它?
所以我想要类似的东西
if((( /* condition A */)&&(/* condition B */ ))|| /* AND OR? */ (( /* condition C */ )&&( /* condition D */)))
(用于确定一个段的至少一侧是否属于另一个段)
所以...在c++中有“AND OR”并且我们应该总是像这样编写丑陋的代码重复:
if(((( /* condition A */)&&(/* condition B */ ))|| (( /* condition C */ )&&( /* condition D */))) || ((( /* condition A */)&&(/* condition B */ )) && (( /* condition C */ )&&( /* condition D */)))
?
I am writting some conditionall if and I want to have something like
if ( /*condition one */) and or ( /* condition two */ )
Is there such operator in C++ and how to write it?
So I want something like
if((( /* condition A */)&&(/* condition B */ ))|| /* AND OR? */ (( /* condition C */ )&&( /* condition D */)))
(for figuring out if at least one side of a segment belongs to another segment)
So... there is on "AND OR" IN c++ AND WE SHALL ALWAYS WRITE UGLY CODE DUPLICATION LIKE THIS:
if(((( /* condition A */)&&(/* condition B */ ))|| (( /* condition C */ )&&( /* condition D */))) || ((( /* condition A */)&&(/* condition B */ )) && (( /* condition C */ )&&( /* condition D */)))
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果你的意思是我认为你的意思,那么在英语中它更常见地写作和/或,它的意思是这样的:
,则表达式整体为真。
如果这就是您的意思,那么答案就是
or
或||
。前两种情况在编程中通常称为“异或”或“异或”:即,如果一个为真,而另一个则不是。
C++ or 运算符是包含 OR,也就是说,如果一个或两个操作数为 true,则为 true
If you mean what I think you mean, then in English it is more commonly written and/or, and what it means is this:
then the expression is as a whole is true.
If that is what you mean, then the answer is simply
or
or||
.The first two cases are typically referred to in programming as an exclusive or, or XOR: that is, if one is true, and the other is not.
The C++ or operator is an inclusive OR, that is, it is true if one or both of the operands are true
如果有两个条件,
A
和B
如果 A 或 B 为真,则 A 和 B 也为真。听起来你只是想要 OR。
If you have two conditions,
A
andB
If A or B is true, A and B is true as well. Sounds like you just want OR.
and or 只是布尔术语中的 or:您可以使用双管道 (||) 运算符。
and or would simply be or in boolean terms: you can use the double pipe (||) operator for that.
只需使用
或
。即使两个条件都为真,它的计算结果也会为true
。换句话说,“或”运算是包含或,而不是排除或。后者要求两个条件之一为真。
我们通常使用
||
运算符,但or
也可以:Just use
or
. It will evaluate totrue
if even if both conditions are true.In other words, the "or" operation is inclusive or, not exclusive or. The latter requires that exactly one of the two conditions be true.
We usually use the
||
operator, butor
also works:并接受带有以下输出的输入
或 接受带有以下输出的输入
因此,如果“和或”意味着它可以是“和”,也可以是“或”,则使用单个“或”可以处理这两种情况,如果您只是验证“true”输出,如
true, true -> true
(也是唯一的 true 输出)已包含在标准or
输出中。如果“and or”意味着它必须是“and”并且它也必须是“or”,如果您仅验证“true”输出,则使用单个“and”可以处理这两种情况,如
true, true -> true
(也是唯一的 true 输出)已包含在标准or
输出中。如果您仅验证“假”输出,则选择哪个运算符的优先级将根据组合的解释而反转。
And takes input with the following output
Or takes the input with the following output
So if "and or" means that it could be "and" and it could be "or", using a single "or" handles both scenarios if your are only verifying "true" output, as
true, true -> true
(and's only true output) is already contained in the standardor
output.If "and or" means that it must be "and" and it must also be "or" using a single "and" handles both scenarios if you are only verifying "true" output, as
true, true -> true
(and's only true output) is already contained in the standardor
output.If you are verifying only "false" output, the precedence of which operator to select is inverted depending on the interpretation of the combination.