垂直管道 ( | ) 在 C++ 中是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10164086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does the vertical pipe ( | ) mean in C++?
提问by quakkels
I have this C++ code in one of my programming books:
我在我的一本编程书中有这个 C++ 代码:
WNDCLASSEX wndClass = { 0 };
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS_HREDRAW | CS_VREDRAW;
What does the single pipe do in C++ windows programming?
C++ windows编程中单管有什么作用?
回答by Zeta
Bitwise OR operator. It will set all bits true that are true in either of both values provided.
按位或运算符。它将设置在提供的两个值中的任何一个中为真的所有位为真。
For example CS_HREDRAW
could be 1 and CS_VREDRAW
could be 2. Then it's very simple to check if they are set by using the bitwise AND operator &
:
例如,CS_HREDRAW
可以是 1,CS_VREDRAW
也可以是 2。然后使用按位 AND 运算符检查它们是否设置非常简单&
:
#define CS_HREDRAW 1
#define CS_VREDRAW 2
#define CS_ANOTHERSTYLE 4
unsigned int style = CS_HREDRAW | CS_VREDRAW;
if(style & CS_HREDRAW){
/* CS_HREDRAW set */
}
if(style & CS_VREDRAW){
/* CS_VREDRAW set */
}
if(style & CS_ANOTHERSTYLE){
/* CS_ANOTHERSTYLE set */
}
See also:
也可以看看:
回答by Nawaz
回答by Michael Foukarakis
It's a bitwise OR operator. For instance,
这是一个按位或运算符。例如,
if( 1 | 2 == 3) {
std::cout << "Woohoo!" << std::endl;
}
will print Woohoo!
.
将打印Woohoo!
。