home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!agate!doc.ic.ac.uk!mrccrc!warwick!bham!bhamvx!mccauleyba
- From: mccauleyba@vax1.bham.ac.uk (Brian McCauley)
- Subject: Re: Just what is so great about streams?
- Sender: usenet@rs6000.bham.ac.uk (USENET News Service)
- Message-ID: <1992Nov17.204453.1@vax1.bham.ac.uk>
- Date: Tue, 17 Nov 1992 20:44:53 GMT
- Lines: 43
- References: <1992Nov12.061942.16473@nuscc.nus.sg> <1992Nov12.171641.13797@aplcen.apl.jhu.edu> <24184@alice.att.com> <mg.721969238@tyrolia>
- Organization: University of Birmingham
-
- In article <mg.721969238@tyrolia>, mg@tyrolia (Michael Golan) writes:
- > Any good reason why
- > cout << fmt("%5d %5d\n") << x << y ;
- > or even
- > cout("%5d,%5d\n") << x << y ;
- > do not exist?
- Yes - nobody has written them.
-
- To implement ostream::operator()() would of course require modification to
- the ostream class and we'd like to avoid that.
-
- A better implementation goes as follows:
-
- struct fmt { const char *form; fmt(const char *f) : form(f) {}};
-
- struct formstream {
- ostream& os; const char *form;
- formstream(ostream& o,const char *f) : os(o),form(f) {}
- preprocess(); postprocess();
- }
-
- formstream operator<<(ostream& o,fmt& f) {return formstream(o,f.form);}
-
- template <class T>
- formstream& operator(formstream& f,const T& t) {
- f.preprocess(); f.os << t; f.postprocess(); return f;
- }
-
- OK I've given you a start now do you want to try to implement it?
-
- > 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.
- It may be a silly question but are you sure you have in-lining switched
- on?
- --
- \\ ( ) No Bullshit! | Email: B.A.McCauley@bham.ac.uk
- . _\\__[oo from | Voice: +44 21 471 3789 (home)
- .__/ \\ /\@ /~) /~[ /\/[ | Fax: +44 21 625 2175 (work)
- . l___\\ /~~) /~~[ / [ | Snail: 197 Harborne Lane,
- # ll l\\ ~~~~ ~ ~ ~ ~ | Birmingham, B29 6SS, UK
- ###LL LL\\ (Brian McCauley) | ICBM: 52.5N 1.9W
-