I've written tons of operator<<(std::ostream &, const T &)
functions -- they're incredibly useful.
I've never written an operator>>(std::istream &, T &)
function in real code or even used the extraction operators for built-in types (OK, maybe for std::string
). Are these appropriate only for short example programs and textbooks? Is operator>>
a failed feature of C++?
Questions have been asked about safely overloading stream operators. What I wonder is if anyone does this in practice.
Even for something simple like reading input from a file in C++ I can't suggest using operator>>
. It's too difficult to write code that is robust in detecting and handling errors in input (or I don't know how).
If you disagree please show a good example of using operator>>
-- maybe by answering that last question I linked to.
op>>
so I accepted that one.
I think stream extractor operators can be very useful when combined with STL algorithms like std::copy
and with the std::istream_iterator
class.
Read this answer to see what I'm talking about.