home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!gatech!ncar!news.miami.edu!rcf.rsmas.miami.edu!SILVIA
- From: silvia@rcf.rsmas.miami.edu
- Newsgroups: comp.lang.c++
- Subject: Re: Comma operator for stream I/O (was: Answers on a postcard...)
- Message-ID: <1992Sep15.203544.26595@news.miami.edu>
- Date: 15 Sep 92 20:35:44 GMT
- References: <1992Sep13.160033.7735@taumet.com>,<4958@holden.lulea.trab.se>
- Sender: news@news.miami.edu (USENET News System)
- Reply-To: silvia@rcf.rsmas.miami.edu
- Organization: RSMAS
- Lines: 49
-
- In article <4958@holden.lulea.trab.se>, jbn@lulea.trab.se (Johan Bengtsson) writes:
- >This is a side-track from the previous discussion. Below I propose
- >an alternate syntax for stream I/O (futile, I know). I'd be curious
- >to know what the net thinks about it.
- >
- >steve@taumet.com (Steve Clamage) writes:
- >:
- >: Personally, I've never seen any example of code
- >: which was improved by using an overloaded comma (which of course
- >: doesn't mean there is no such code).
- >
- >Since I am also in search of an example where the comma operator would be
- >a good choice:
- >
- >Would the comma operator have been a good choice for stream I/O?
- >I.e. instead of the rather hard-to-read expression
- >
- > cout << "The value is " << value << endl;
- >
- >you would write
- >
- > cout, "The value is", value, endl;
- >
- >The precedence is just right (very low).
- >
- >The comma operator could be used for input as well:
- >
- > int i; float f; char c;
- > cin, i, f, c;
- >
- >Finally, for iostreams, you would invoke the methods
- >
- > istream& iostream::in();
- > ostream& iostream::out();
- >
- >to select input or output, like this
- >
- > iostream io(...);
- > io.out(), "The value is", value, endl;
- > io.in(), i, f, c;
- >
- >Is this technique commonly used in MI classes (base class selector methods,
- >to do controlled up-casting)? Just curious...
- >
- >--
- >--------------------------------------------------------------------------
- >| Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden |
- >| Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490 |
- >--------------------------------------------------------------------------
-