cin/streambuf-problem

R. Sinoradzki sinoradz@student.uni-kl.de
Fri May 18 14:49:00 GMT 2001


Hi,

I have this little program. It does not behave as
expected with gcc-3.0 and it's stdlib.
If I type for example "hello" the loop runs 5 times,
before the next 'cin' because 'cin.rdbuf()->in_avail()'
reports only 1.

With gcc-2.95.4 cin.rdbuf()->in_avail() returns 6
and it works as expected.

My gcc-3.0pre is an about 10 days old CVS-version. Perhaps
this is a well-known problem.

bye, Ralf

/////////////////////////////////////////////////////////////

#include <fstream>
#include <iostream>

using namespace std;

int main(){
    int input=0;
    do{
	if (cin.fail()){
	    cin.clear();
	    cin.ignore(cin.rdbuf()->in_avail(),'\n'); // seems to bug
	    cout<<"bad input." << endl;
	}
	cout<<"enter a number: ";
	cin>>input;
	cout << input << endl;
    }
    while(input!=3);
    return 0;
}

//////////////////////////////////////////////////////////



More information about the Libstdc++ mailing list