This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

cin/streambuf-problem


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;
}

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]