Why are bitwise shifts (<< and>>) used for cout and cin?

后端 未结 13 1693
眼角桃花
眼角桃花 2020-12-02 16:16

Question is in the title really; I\'m sure there is something logical, but for now I\'m stumped!

13条回答
  •  一向
    一向 (楼主)
    2020-12-02 17:12

    This answer is unsatisfying but correct: they aren't bitwise operators.

    The meaning of the operator is determined by the data-type that appears on its left. In the case of cin and cout (and other stream types) << and >> operators move values to and from streams. In the case that the left operand is an integer, the operation is the bitwise operation that you already know from C.

    The meaning of the operator is not fixed, although its precedence is.

提交回复
热议问题