Does anyone actually use stream extraction operators?

后端 未结 7 2145
余生分开走
余生分开走 2020-12-25 14:26

I\'ve written tons of operator<<(std::ostream &, const T &) functions -- they\'re incredibly useful.

I\'ve never written an operator

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-25 15:18

    operator>> is useful in converting numbers in text form to an internal representation.

    It can also be useful in loading data for objects. Unlike scanf, which cannot be overloaded for different types, objects can overload operator>>. Thus it provides more data hiding for loading objects, the internal representation does not need to be known in order to read data into the object.

提交回复
热议问题