home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!usc!wupost!darwin.sura.net!jvnc.net!princeton!csservices!tyrolia!mg
- From: mg@tyrolia (Michael Golan)
- Subject: Re: Just what is so great about streams?
- Message-ID: <mg.721969238@tyrolia>
- Sender: news@csservices.Princeton.EDU (USENET News System)
- Organization: Princeton University, Dept. of Computer Science
- References: <1992Nov12.061942.16473@nuscc.nus.sg> <1992Nov12.171641.13797@aplcen.apl.jhu.edu> <24184@alice.att.com>
- Date: 17 Nov 92 03:00:38 GMT
- Lines: 27
-
- 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.
-
- Obvious implementation
- fmt saves the format string in the stream class and prints the
- text upto the first '%'. Then every << should call
- pre_process_format() to extract the %X and set up the correct internal
- parms, and post_process_format which continues the output of the fmt string.
- Of course %*.*f can not be handled, but thats ok.
-
- Also, the book fails to mention that cin.get(c) is slower than getchar()
- by a factor of 2 or so. Same for fread vs. cin.read(), at least in the
- simple timing I made under BC++3.0. This is a serious problem, e.g., when
- you read a 32k chunks of bin data into memory.
-
- Michael
-
-