From Bugzilla Helper: User-Agent: Mozilla/5.0 Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20030131 Description of problem: The streambuf::in_avail() method always returns zero. This simple example program downloaded from cplusplus.com demonstrates the problem: // 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; return 0; } // End of in_avail () example When compiling and running on the supplied system/architecture, the program will always report "0 additional characters in input buffer" no matter how many there really are. This is true for all stream classes that use streambuf. Version-Release number of selected component (if applicable): libstdc++-3.2.2-5 How reproducible: Always Steps to Reproduce: 1. Compile the example code 2. Execute the example code 3. Enter a short phrase when prompted Actual Results: The first character entered is properly reported, and "0 additional characters in input buffer" is always reported. Expected Results: The actual number of characters remaining in the buffer being reported correctly. Additional info: This bug existed in previous standard c++ library packages. Considering that there is no other way to see if input is waiting on an input stream, this problem really needs to be fixed. It's not really possible to use C++ streams in a good user interface as long as this bug exists.
This isn't a bug. basic_streambuf::showmanyc Default behavior: Returns zero. basic_streambuf::in_avail() If a read position is available, returns egptr() - gptr(). Otherwise returns showmanyc() filebuf::showmanyc(); Behaves the same as basic_streambuf::showmanyc() Note:An implementation might well provide an overriding definition for this function signature if it can determine that more characters can be read from the input sequence. This is implementation-specific behavior. If you want accurate in_avail semantics with GNU C++, you should use streams with unbuffered io, ie std::basic_[io]fstream with a file name. This will work as you expect. best, -benjamin