Topic: stream help


Author: heknat@ursa.calvin.edu (Nathaniel Hekman)
Date: 20 Jan 1995 20:51:23 GMT
Raw View
I have what I believe to be a fairly simple question, but no one has
been able to answer me around here.  I am looking for some way to
check if a stream, say cin, is "empty" or not.  As an example, I'd
like to be able to go through a loop, and periodically check if the
user has hit some keys.  Of course, if I use the line

   cin >> str;   // where str is a char*

execution will hang at that point until there actually _is_ something
to assign to str.  I want to be able to check before writing that line
to make sure there is something "waiting" in cin; if there is, I'll
assign it to str, else I skip on to the next instruction.

Someone suggested I'm trying to read keystrokes instead of a stream.
This is not the case.  Although in the above example I cuold get that
to work (interrupt at each keystroke and call some function), I would
like something more general, that I cuold use with _any_ stream, be it
cin, an ifstream (like "/dev/ttya", a serial port), or any other
instantiation of the stream class.

Any thoughts?  Please email me at heknat@calvin.edu, as I do not
regularly read this newsgroup.  Thank you!

Nate



  ***  heknat@Calvin.EDU  *********************  nhekma49@Calvin.EDU  ***
  Nathaniel M. Hekman, Computer Centre   | History goes its way
  Calvin College       Tel: 616.957.6144 |   without much prompting
  Grand Rapids MI USA  FAX: 616.957.8551 | from me.
        #include <std.disclaimer.h>      |