Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

reopen cin?

89 views
Skip to first unread message

Dr Richard J. Reid

unread,
Oct 30, 1991, 4:52:26 PM10/30/91
to
If cin is from the keyboard, there may be more input
following the synthesized eof from the ^D.

How do you get this stream restarted?
The istream set's, unset's and clear's
don't seem to do it.

Thanks,

Dick

Jerry Schwarz

unread,
Oct 31, 1991, 8:51:52 PM10/31/91
to

This is system dependent and the poster didn't indicate the
system, but cin.clear() should work. I have tested the attached
program on a UNIX system with AT&T version's of iostreams.

Jerry Schwarz
----------------------------------
#include <iostream.h>

int main()
{
for(;;) {
if ( cin.eof() ) {
cout << "EOF" << endl;
cin.clear();
}
char c ;
if ( cin.get(c) ) cout.put(c) ;
}
}

Dr Richard J. Reid

unread,
Nov 1, 1991, 8:31:06 AM11/1/91
to

Jerry--

Yes, that works okay in cfront and TC++.
In g++ where the problem first arose an additional
action is required:

cin.clear();
rewind ( _iob ); // Seems quite out of place, doesn't it?
// cfront also accepts but doesn't
// require this rewind.

Dick

0 new messages