Article View: comp.os.os2.programmer
Article #2182GCC 2.2.2 cin bug?
From: Andrew Bros
Date: Tue, 29 Sep 1992 14:33
Date: Tue, 29 Sep 1992 14:33
38 lines
1880 bytes
1880 bytes
I was working through the Waite Group's C++ Primer (1991), and found
that one of the examples was not working right. The problem seems to
be that the cin is not returning 0 as expected on invalid input. I
don't have any real reference book on C++, so I can't be sure things
are supposed to work like this, but my book says (p. 281):
"If, however, the input data does not match cin's expectactions, the
returned value is 0, or false."
I noticed when the expected data is an int, the expression functions
as expected.
// Check for a cin bug in gcc/2
// Andrew Bros (bros@convex.com)
// September 28, 1992
#include <iostream.h>
int main (void)
{
double x;
iostream * rtn;
cout << "Enter a number (q to quit): ";
while (rtn = cin >> x) {
cout << "X = " << x << "\n";
cout << "Next number (q to quit): ";
}
if (rtn == 0) {
cout << "cin returned " << rtn << "\n";
}
}
--
Andrew Bros bros@convex.com
System Integration Group Convex Computer Corporation
It does not do to leave a live dragon out of your calculations,
if you live near him. - JRR Tolkien, The Hobbit.
Technical Details
Message-ID:
<1992Sep29.143308.6747@news.eng.convex.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!convex!convex!brosShow Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!convex!convex!bros
From: Andrew Bros <bros@convex.COM>
Subject: GCC 2.2.2 cin bug?
Originator: bros@neptune.convex.com
Sender: usenet@news.eng.convex.com (news access account)
Message-ID: <1992Sep29.143308.6747@news.eng.convex.com>
Date: Tue, 29 Sep 1992 14:33:08 GMT
Reply-To: bros@convex.COM (Andrew Bros)
Nntp-Posting-Host: neptune.convex.com
Organization: Convex Computer Corporation, Richardson, TX
X-Disclaimer: This message was written by a user at CONVEX Computer
Corp. The opinions expressed are those of the user and
not necessarily those of CONVEX.
Lines: 38