Article View: gnu.gcc.bug
Article #1154Re: "cin" bug?
From: Joe Buck
Date: Tue, 15 Sep 1992 20:56
Date: Tue, 15 Sep 1992 20:56
46 lines
2293 bytes
2293 bytes
In article <9209150106.AA15049@brain.diag.amdahl.com> brm30@diag.amdahl.COM (Brian Moyle) writes: >Hello, > > I'm fairly new to C++ programming, but I've run into a little >problem that seems to qualify as a bug. The following program was >taken from The Waite Group's, "C++ Programming," by John Berry, >copyright 1988 (fourth printing -- 1990). On page 44, the following >paragraph provides an explanation of how the 'while' loop is exited: Brian, I'm about to flame John Berry. This is not directed at you. This has got to be the worst C++ book I have ever seen. Run, not walk, away from it. Do your best to forget whatever it said. Mr. Berry is clearly not competent to write a C++ text. Of the 10 or so C++ books I have reviewed, this one is by far the worst. The fact that it's now in its fourth printing gives evidence to the old adage: there's a sucker born every minute. The program in question is incorrect; you'll get the same symptoms if you build it with cfront. He is relying on a stupid hack, assuming that if he says double x, y; char op; that if he then says cin >> x >> opr >> y; and you type "exit", the x character will wind up in "opr". But that is not how streams work! A double cannot begin with "e", therefore nothing is consumed from cin. The e remains on the input, and opr does not change. The only way to read more stuff from cin is to clear its error flag. Perhaps an early streams implementation he used happened to work this way. But no competent programmer would ever rely on such an accidental feature. Even if this program did happen to work, Mr. Berry should be condemned for teaching beginners to program this way. What an ugly, disgusting kludge. -- Joe Buck jbuck@ohm.berkeley.edu
Technical Details
Message-ID:
<195illINN2ta@agate.berkeley.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!wupost!spool.mu.edu!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!forney.berkeley.edu!jbuckReferences:
<9209150106.AA15049@brain.diag.amdahl.com>Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!spool.mu.edu!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!forney.berkeley.edu!jbuck From: jbuck@forney.berkeley.edu (Joe Buck) Subject: Re: "cin" bug? Message-ID: <195illINN2ta@agate.berkeley.edu> Sender: gnulists@ai.mit.edu Organization: U. C. Berkeley References: <9209150106.AA15049@brain.diag.amdahl.com> Distribution: gnu Date: Tue, 15 Sep 1992 20:56:21 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 47