How do I find out if new input from cin input stream (or possibly stdin) is
available?

I was expecting I could use the is_avail() member function of istream for
this.
But the sample code from:
http://www.cplusplus.com/ref/iostream/streambuf/in_avail.html
seems to indicate that is_avail() always returns 0 !!?

//http://www.cplusplus.com/ref/iostream/streambuf/in_avail.html

// in_avail () example
#include <iostream>
using namespace std;

int main () {

  streamsize size;
  char ch;

  streambuf * pbuf;
  pbuf = cin.rdbuf();

  cout << "Please enter some characters: ";
  cin >> ch;

  size = pbuf->in_avail();

  cout << "The first character you entered is: " << ch << endl;
  cout << size << " additional characters in input buffer" << endl;
  cout << cin.rdbuf()->in_avail() << " additional characters in input
buffer" << endl;

  cin >> ch;
  size = pbuf->in_avail();
  cout << "The second character you entered is: " << ch << endl;
  cout << size << " additional characters in input buffer" << endl;
  cout << cin.rdbuf()->in_avail() << " additional characters in input
buffer" << endl;

  return 0;
}


After compiling under cygwin (dll 1.3.1-1) and running I get:
$ gcc test.cpp /lib/libstdc++.a
$ ./a.exe
Please enter some characters: cygwin
The first character you entered is: c
0 additional characters in input buffer
The second character you entered is: y
0 additional characters in input buffer

I was expecting the in_avail() function to return 6 after the first cin>>ch;
instead I get 0 !?
Are my expectations wrong?
Is there another non-blocking way to find out if more keystrokes are
available or not?

Berni.


--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

Reply via email to