home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13693 < prev    next >
Encoding:
Text File  |  1992-09-15  |  1.3 KB  |  39 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Comma operator for stream I/O (was: Answers on a postcard...)
  5. Message-ID: <1992Sep15.174644.12710@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1992Sep13.160033.7735@taumet.com> <4958@holden.lulea.trab.se>
  8. Date: Tue, 15 Sep 1992 17:46:44 GMT
  9. Lines: 28
  10.  
  11. jbn@lulea.trab.se (Johan Bengtsson) writes:
  12.  
  13. >Since I am also in search of an example where the comma operator would be
  14. >a good choice:
  15.  
  16. >Would the comma operator have been a good choice for stream I/O?
  17. >I.e. instead of the rather hard-to-read expression
  18.  
  19. >  cout << "The value is " << value << endl;
  20.  
  21. >you would write
  22.  
  23. >  cout, "The value is", value, endl;
  24.  
  25. >The precedence is just right (very low).
  26.  
  27. The reason why << and >> are used is historical.  Stroustrup explains
  28. that of the available operators, they seemed to be the best choice.
  29. At that time (1985), the comma operator could not be overloaded, so
  30. was not a possibility.  Perhaps comma would have been used otherwise.
  31.  
  32. I've been using << and >> for so long now that I find them easier
  33. to read than the comma example.  I must admit, though, that when I
  34. started in C++ I found << and >> quite bizarre and unreadable.
  35. -- 
  36.  
  37. Steve Clamage, TauMetric Corp, steve@taumet.com
  38. Vice Chair, ANSI C++ Committee, X3J16
  39.