23

I have this C++ code in one of my programming books:

WNDCLASSEX wndClass = { 0 };
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style =  CS_HREDRAW | CS_VREDRAW;

What does the single pipe do in C++ windows programming?

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
quakkels
  • 11,676
  • 24
  • 92
  • 149

4 Answers4

34

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 &:

#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:

Zeta
  • 103,620
  • 13
  • 194
  • 236
11

| is called bitwise OR operator.

|| is called logical OR operator.

Nawaz
  • 353,942
  • 115
  • 666
  • 851
8

In C++20, it can also be the pipe operator of range adaptor closure objects. I.e. chaining together operations on ranges. Read more about it here: https://en.cppreference.com/w/cpp/ranges#Range_adaptor_closure_objects

Iizuki
  • 354
  • 1
  • 6
  • 12
5

It's a bitwise OR operator. For instance,

if( 1 | 2 == 3) {
    std::cout << "Woohoo!" << std::endl;
}

will print Woohoo!.

Michael Foukarakis
  • 39,737
  • 6
  • 87
  • 123