home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!sunic!hagbard!loglule!jbn
- From: jbn@lulea.trab.se (Johan Bengtsson)
- Newsgroups: comp.lang.c++
- Subject: Comma operator for stream I/O (was: Answers on a postcard...)
- Message-ID: <4958@holden.lulea.trab.se>
- Date: 14 Sep 92 15:26:50 GMT
- References: <1992Sep13.160033.7735@taumet.com>
- Organization: Telia Research AB, Aurorum 6, 951 75 Lulea, Sweden
- Lines: 48
- X-Newsreader: Tin 1.1 PL4
-
- 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 |
- --------------------------------------------------------------------------
-