home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16443 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.4 KB  |  52 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!spool.mu.edu!umn.edu!csus.edu!borland.com!pete
  3. From: pete@borland.com (Pete Becker)
  4. Subject: Re: Just what is so great about streams?
  5. Message-ID: <1992Nov17.170455.13870@borland.com>
  6. Originator: pete@genghis.borland.com
  7. Sender: news@borland.com (News Admin)
  8. Organization: Borland International
  9. References: <1992Nov12.171641.13797@aplcen.apl.jhu.edu> <24184@alice.att.com> <mg.721969238@tyrolia>
  10. Date: Tue, 17 Nov 1992 17:04:55 GMT
  11. Lines: 39
  12.  
  13. In article <mg.721969238@tyrolia> mg@tyrolia (Michael Golan) writes:
  14. >Hi!
  15. >
  16. >Any good reason why
  17. >  cout << fmt("%5d %5d\n") << x << y ;
  18. >or even
  19. >  cout("%5d,%5d\n") << x << y ;
  20. >do not exist?
  21. >
  22. >  cout << dec(5) << x  << " " << dec(5) << y << "\n" ;
  23. >
  24. >is not type-safer, is it? the formatting is ignored if x,y have non-int
  25. >type, just like %5d would be.
  26. >
  27.  
  28.     Such a construct quickly becomes meaningless in the presence of
  29. user-defined inserters:
  30.  
  31.     class complex
  32.     {
  33.     public:
  34.     double real, imag;
  35.     };
  36.  
  37.     ostream& operator << ( ostream& os, complex c )
  38.     {
  39.     return os << '(' << c.real << ',' << c.imag;
  40.     }
  41.  
  42. Now, what should the library do with this?
  43.  
  44.     complex c1, c2;
  45.     cout << fmt( "%f %f %5d" ) << c1 << c2 << 3;
  46.  
  47. Should it apply only one specifier for each inserter?  Keeping in mind, of
  48. course, that each inserter for a complex is in reality two inserters for a
  49. double...
  50.     -- Pete
  51.  
  52.