home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!spool.mu.edu!umn.edu!csus.edu!borland.com!pete
- From: pete@borland.com (Pete Becker)
- Subject: Re: Just what is so great about streams?
- Message-ID: <1992Nov17.170455.13870@borland.com>
- Originator: pete@genghis.borland.com
- Sender: news@borland.com (News Admin)
- Organization: Borland International
- References: <1992Nov12.171641.13797@aplcen.apl.jhu.edu> <24184@alice.att.com> <mg.721969238@tyrolia>
- Date: Tue, 17 Nov 1992 17:04:55 GMT
- Lines: 39
-
- In article <mg.721969238@tyrolia> mg@tyrolia (Michael Golan) writes:
- >Hi!
- >
- >Any good reason why
- > cout << fmt("%5d %5d\n") << x << y ;
- >or even
- > cout("%5d,%5d\n") << x << y ;
- >do not exist?
- >
- > cout << dec(5) << x << " " << dec(5) << y << "\n" ;
- >
- >is not type-safer, is it? the formatting is ignored if x,y have non-int
- >type, just like %5d would be.
- >
-
- Such a construct quickly becomes meaningless in the presence of
- user-defined inserters:
-
- class complex
- {
- public:
- double real, imag;
- };
-
- ostream& operator << ( ostream& os, complex c )
- {
- return os << '(' << c.real << ',' << c.imag;
- }
-
- Now, what should the library do with this?
-
- complex c1, c2;
- cout << fmt( "%f %f %5d" ) << c1 << c2 << 3;
-
- Should it apply only one specifier for each inserter? Keeping in mind, of
- course, that each inserter for a complex is in reality two inserters for a
- double...
- -- Pete
-
-