What is "operator<<" called?
I know the names of most of the operators but not sure what operator<<
and operato开发者_StackOverflow社区r>>
are called.
i.e.
operator=() // the assignment operator
operator==() // the equality of comparison operator
operator++() // the increment operator
operator--() // decrement operator etc.
operator<() // the less-than operator
and so forth...
<<
is both the insertion operator and the left-shift operator.
>>
is the extraction operator and the right-shift operator.
In the context of iostreams, they are considered to be stream insertion/extraction. In the context of bit-shifting, they are left-shift and right-shift.
In C++ Streams,
<<
is insertion operator.>>
is extraction operator.
In Binary Operations,
- Right shift (>>)
- Left shift (<<)
<<
left shift
>>
right shift
<< = Bitwise left shift
>> = Bitwise right shift
Bit Shift Operators
The original names were left shift operator (<<
) and right shift operator (>>
), but with their meanings perverted by streams into insertion and extraction, you could argue that even in bitwise operations <<
inserts bits on the right while >>
extracts them. Consequently, I almost always refer to them as the insertion and extraction operators.
<< is the 'left-shift' operator. It shifts its first operand left by the number of bits specified by its second operand.
They are called the Guillemet Left and Guillemet Right symbols :)
精彩评论