This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
cin/streambuf-problem
- To: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Subject: cin/streambuf-problem
- From: "R. Sinoradzki" <sinoradz at student dot uni-kl dot de>
- Date: Fri, 18 May 2001 23:53:43 +0200
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;
}
//////////////////////////////////////////////////////////