home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13708 < prev    next >
Encoding:
Internet Message Format  |  1992-09-15  |  2.1 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!gatech!ncar!news.miami.edu!rcf.rsmas.miami.edu!SILVIA
  2. From: silvia@rcf.rsmas.miami.edu
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Comma operator for stream I/O (was: Answers on a postcard...)
  5. Message-ID: <1992Sep15.203544.26595@news.miami.edu>
  6. Date: 15 Sep 92 20:35:44 GMT
  7. References: <1992Sep13.160033.7735@taumet.com>,<4958@holden.lulea.trab.se>
  8. Sender: news@news.miami.edu (USENET News System)
  9. Reply-To: silvia@rcf.rsmas.miami.edu
  10. Organization: RSMAS
  11. Lines: 49
  12.  
  13. In article <4958@holden.lulea.trab.se>, jbn@lulea.trab.se (Johan Bengtsson) writes:
  14. >This is a side-track from the previous discussion.  Below I propose
  15. >an alternate syntax for stream I/O (futile, I know).  I'd be curious
  16. >to know what the net thinks about it.
  17. >
  18. >steve@taumet.com (Steve Clamage) writes:
  19. >: 
  20. >: Personally, I've never seen any example of code
  21. >: which was improved by using an overloaded comma (which of course
  22. >: doesn't mean there is no such code).
  23. >
  24. >Since I am also in search of an example where the comma operator would be
  25. >a good choice:
  26. >
  27. >Would the comma operator have been a good choice for stream I/O?
  28. >I.e. instead of the rather hard-to-read expression
  29. >
  30. >  cout << "The value is " << value << endl;
  31. >
  32. >you would write
  33. >
  34. >  cout, "The value is", value, endl;
  35. >
  36. >The precedence is just right (very low).
  37. >
  38. >The comma operator could be used for input as well:
  39. >
  40. >  int i; float f; char c;
  41. >  cin, i, f, c;
  42. >
  43. >Finally, for iostreams, you would invoke the methods
  44. >
  45. >  istream& iostream::in();
  46. >  ostream& iostream::out();
  47. >
  48. >to select input or output, like this
  49. >
  50. >  iostream io(...);
  51. >  io.out(), "The value is", value, endl;
  52. >  io.in(), i, f, c;
  53. >
  54. >Is this technique commonly used in MI classes (base class selector methods,
  55. >to do controlled up-casting)?  Just curious...
  56. >
  57. >-- 
  58. >--------------------------------------------------------------------------
  59. >| Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
  60. >| Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490  |
  61. >--------------------------------------------------------------------------
  62.