C++ 什么叫“运算符<<”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3281666/
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 is "operator<<" called?
提问by ScaryAardvark
I know the names of most of the operators but not sure what operator<<
and operator>>
are called.
我所知道的大多数运营商的名字,但不知道什么operator<<
和operator>>
被调用。
i.e.
IE
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...
等等……
采纳答案by Mitch Wheat
<<
left shift
<<
左移
>>
right shift
>>
右移
回答by Scott Stafford
<<
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.
在 iostream 的上下文中,它们被认为是流插入/提取。在位移的上下文中,它们是左移和右移。
回答by cpx
In C++ Streams,
在 C++ 流中,
<<
is insertion operator.>>
is extraction operator.
<<
是插入运算符。>>
是提取运算符。
In Binary Operations,
在二元运算中,
- Right shift (>>)
- Left shift (<<)
- 右移 (>>)
- 左移 (<<)
回答by GaryDevenay
<< = Bitwise left shift
>> = Bitwise right shift
回答by davbryn
回答by Jon Purdy
The original names were left shiftoperator (<<
) and right shiftoperator (>>
), but with their meanings perverted by streams into insertion and extraction, you could argue that even in bitwise operations <<
insertsbits on the right while >>
extractsthem. Consequently, I almost always refer to them as the insertionand extractionoperators.
最初的名称是左移运算符 ( <<
) 和右移运算符 ( >>
),但由于它们的含义被流扭曲为插入和提取,您可能会争辩说,即使在按位运算中,在提取它们时也会在右侧<<
插入位。因此,我几乎总是将它们称为插入和提取运算符。>>
回答by Fraser
<< is the 'left-shift' operator. It shifts its first operand left by the number of bits specified by its second operand.
<< 是“左移”运算符。它将第一个操作数左移第二个操作数指定的位数。
回答by Robben_Ford_Fan_boy
They are called the Guillemet Left and Guillemet Right symbols :)
它们被称为 Guillemet Left 和 Guillemet Right 符号:)