TITLE: stream shift operators for text (Newsgroups: comp.lang.c++,comp.lang.c++.moderated, 2 Jan 99) CLAMAGE: clamage@Eng.Sun.COM (Steve Clamage) >|> If you overload shift operators for I/O on a class, readers of your >|> code have a right to expect that formatted text I/O is involved. >|> If that isn't the case, users of your class and readers of your >|> code will be confused. KANZE: kanze@gabi-soft.fr (J. Kanze) >Do they, or do they only have the right to expect that it isn't pure >binary (bit copying) IO? I thought I knew the answer, but both you and >Nathan Meyers have posted that the overloaded shift operators are only >for text, so I'm not so sure. CLAMAGE: Steve Clamage If you go back to "The C++ Programming Language" first edition (1986), the shift operators for I/O are described only for text. The first release of iostreams (1990) used shift operators only for text. All subsequent releases of iostreams, including in the standard, use shift operators only for text. (With the exception of copying one complete stream to another.) In all cases, non-text I/O used explicit function calls (read, write, get, put) instead of overloaded operators. I claim that the traditional use of shift operators is for text, and the traditional way to do binary I/O is via the ordinary function calls. If you overload some shift operators for binary I/O, leaving the text I/O operators in place, I claim that the program will be more difficult to understand and maintain. Users will either be surprised at some results, or will have to continually check the documentation to find out whether a particular operation is for text or binary. In the presence of of implicit type conversions, finding that out can be difficult.