Does anyone actually use stream extraction operators?

后端 未结 7 2129
余生分开走
余生分开走 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:21

    I never write them, and quite rarely use the "built-in" ones. The extraction operators are pretty useless for reading interactive user input, because it is too easy for a stream to go bad. Writing a custom parsing routine is almost always easier and more robust. And when it comes to serialisation, if I want to save something as text, I do it to an industry-standard format such as XML, which the extraction operators are notably ill-suited to read. Otherwise I store the data on a database or in binary file, which once again are ill-suited for use with extractors.

提交回复
热议问题