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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!usc!wupost!darwin.sura.net!jvnc.net!princeton!csservices!tyrolia!mg
  3. From: mg@tyrolia (Michael Golan)
  4. Subject: Re: Just what is so great about streams?
  5. Message-ID: <mg.721969238@tyrolia>
  6. Sender: news@csservices.Princeton.EDU (USENET News System)
  7. Organization: Princeton University, Dept. of Computer Science
  8. References: <1992Nov12.061942.16473@nuscc.nus.sg> <1992Nov12.171641.13797@aplcen.apl.jhu.edu> <24184@alice.att.com>
  9. Date: 17 Nov 92 03:00:38 GMT
  10. Lines: 27
  11.  
  12. Hi!
  13.  
  14. Any good reason why
  15.   cout << fmt("%5d %5d\n") << x << y ;
  16. or even
  17.   cout("%5d,%5d\n") << x << y ;
  18. do not exist?
  19.  
  20.   cout << dec(5) << x  << " " << dec(5) << y << "\n" ;
  21.  
  22. is not type-safer, is it? the formatting is ignored if x,y have non-int
  23. type, just like %5d would be.
  24.  
  25. Obvious implementation
  26. fmt saves the format string in the stream class and prints the 
  27. text upto the first '%'. Then every << should call
  28. pre_process_format() to extract the %X and set up the correct internal
  29. parms, and post_process_format which continues the output of the fmt string.
  30. Of course %*.*f can not be handled, but thats ok.
  31.  
  32. Also, the book fails to mention that cin.get(c) is slower than getchar()
  33. by a factor of 2 or so. Same for fread vs. cin.read(), at least in the
  34. simple timing I made under BC++3.0. This is a serious problem, e.g., when
  35. you read a 32k chunks of bin data into memory. 
  36.  
  37. Michael
  38.  
  39.