Mail Archives: djgpp/1999/03/17/16:10:38
From: | richard_fa AT yahoo DOT com
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | clear the state of cin
|
Date: | Wed, 17 Mar 1999 20:26:58 GMT
|
Organization: | Deja News - The Leader in Internet Discussion
|
Lines: | 50
|
Message-ID: | <7cp369$1ir$1@nnrp1.dejanews.com>
|
NNTP-Posting-Host: | 198.85.204.20
|
X-Article-Creation-Date: | Wed Mar 17 20:26:58 1999 GMT
|
X-Http-User-Agent: | Mozilla/4.5 [en] (Win95; I)
|
X-Http-Proxy: | 1.0 x11.dejanews.com:80 (Squid/1.1.22) for client 198.85.204.20
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
please help with the following little problem. I'd like to use "eof" as a
sentinel for some simple test programs as follows:
#include <iostream.h>
int main() {
int q;
while(cin >> q)
cout << " echo of q: " << q << " ";
cin.clear(); // clears the cin stream eof flag so
// we can use cin again
cout << "another input loop\n";
while(cin >> q)
cout << " echo of q: " << q << " ";
return 0;
}
I expect this code to give the following output (Control-Z is the "eof" marker
on PCs; it's Control-D with Unix):
9
echo of q: 9 7
echo of q: 7 ^Z
another input loop
1
echo of q: 1 2
echo of q: 2 ^Z
which it does under Turbo C/C++ 3.0 for DOS. (although I've learned an odd
thing, the code as written does not work if the cout statement which prints
the line "another input loop" is removed. even though the cin object's state
has been cleared, the second while loop does not execute unless something --
even just sending an "endl" -- is sent to the cout object.)
my foremost question then is why does this code not work using DJGPP, v2.02?
I've read the "info" under iostream -- there's a section on "Checking the
state of a stream", and it seems to say that the above should work, just as
it does under Turbo C/C++.
what am I missing here? thanks in advance.
--
Fred Richard
frichard_cvcc AT yahoo DOT com
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
- Raw text -