delorie.com/archives/browse.cgi | search |
Mailing-List: | contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm |
List-Subscribe: | <mailto:cygwin-subscribe AT sources DOT redhat DOT com> |
List-Archive: | <http://sources.redhat.com/ml/cygwin/> |
List-Post: | <mailto:cygwin AT sources DOT redhat DOT com> |
List-Help: | <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs> |
Sender: | cygwin-owner AT sources DOT redhat DOT com |
Delivered-To: | mailing list cygwin AT sources DOT redhat DOT com |
Message-ID: | <001301c0d634$0eaf8040$0201a8c0@LLDDB> |
From: | "Berni Joss" <berni DOT joss AT urbanet DOT ch> |
To: | <cygwin AT cygwin DOT com> |
Subject: | kbhit() with streambuf::is_avail() |
Date: | Sun, 6 May 2001 15:54:23 +0200 |
MIME-Version: | 1.0 |
X-Priority: | 3 |
X-MSMail-Priority: | Normal |
X-Mailer: | Microsoft Outlook Express 5.50.4522.1200 |
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4522.1200 |
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
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |