垂直管道(|)在C ++中是什么意思? [英] What does the vertical pipe ( | ) mean in C++?
本文介绍了垂直管道(|)在C ++中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的一本编程书籍中都包含以下C ++代码:
I have this C++ code in one of my programming books:
WNDCLASSEX wndClass = { 0 };
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS_HREDRAW | CS_VREDRAW;
在C ++ Windows编程中,单个管道有什么作用?
What does the single pipe do in C++ windows programming?
推荐答案
按位或运算符.它将设置所有提供的两个值中都为真的所有位为真.
Bitwise OR operator. It will set all bits true that are true in either of both values provided.
例如,CS_HREDRAW
可以为1,CS_VREDRAW
可以为2.然后使用按位AND运算符&
来检查它们是否设置非常简单:
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 &
:
#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 */
}
另请参阅:
- Wikipedia: Bitwise operation (Section OR)
- Wikipedia: Mask (computing) Section( Common bitmask functions)
这篇关于垂直管道(|)在C ++中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文