When setting 2 or more stream flags together , why is the '|' operator used instead of &?
Wouldn't a & make more sense ?Code:cout.setf(ios::showpos | ios::showpoint);
Is there a logical explanation for it ?
When setting 2 or more stream flags together , why is the '|' operator used instead of &?
Wouldn't a & make more sense ?Code:cout.setf(ios::showpos | ios::showpoint);
Is there a logical explanation for it ?
It is used to set certain bits. If you have two flags:
00100000
00010000
and you want to merge them together into:
00110000
you use bitwise or. The result of & would be 00000000.
You could also use + instead, but if the same flag appears 2 times the result will be different than expected (some unwanted flag will be set).
*Thanks*
I totally overlooked the low level..