When Created: 01/27/2003 16:17:48
Against DJGPP version: 2.03
By whom: email@example.com
Abstract: iostream get failure problem
Am not sure if you'd consider this a bug or not since iostream details are sketchy, but I have 3 other C++ compilers that handle the same code without failing while djgpp doesn't seem to. Just downloaded the djgpp compiler files again so I assume I am working with the latest version. A code example is given below.
If I run a program with the following code and simply hit enter at the command prompt with no characters on the line, the failbit gets set. Both versions of get below show the failbit set after calling them. There's code in istream.tcc that says:
The state of the stream then becomes corrupt and no more input can get sent to the program. I don't think get(char_type* __s, streamsize __n, char_type __delim)
should return a fail here unless the next character in the stream is not the __delim character.
As I mentioned, I have three other C++ compiler that allow me to use the following code and enter either a string or simply a carriage return without failing. When I try this code with djgpp, it fails and goes into an infinite loop, never reading any more input from cin. Would love to see this fixed to be more consistent with the other compilers and so I don't have to set up a special case for djgpp iostream handling in all my files using get. Thank you.
bool done = false;
while (done == false)
cout << endl;
cout << ">> ";
cin.get (temp, 255, '\n');
cout << temp << endl;
//code here to do some work based on each input string entered by user and
//to set done to true when finished (for example when user types exit).
Workaround added: 07/19/2004 13:58:07
By whom: firstname.lastname@example.org
This bug occurs whenever the delimiting character (whether '\n' or
anything else) is the first character in the yet-to-be-processed input
stream. Change the code to:
if(stream->peek()!= delim) stream->get(buf,count,delim);
This will work on all compilers.
FYI, GNU g++ under Linux doesn't have this problem. Wish I could find the
source for the c++ lib in djgpp...
Note added: 03/21/2007 09:09:58
By whom: email@example.com