This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
bug in istream.get(b,c,d) ?
- From: "Mark J. Reed" <mark dot reed at turner dot com>
- To: libstdc++ at sourceware dot cygnus dot com
- Date: Wed, 18 Sep 2002 16:43:41 -0400
- Subject: bug in istream.get(b,c,d) ?
If a get(buffer, count, delim) call reads 0 characters
(because the next character on the stream is a delimiter),
then a subsequent call to get(void) returns EOF even though
there are more characters on the stream to be read. I
don't have the C++ specification, so I'm not sure if this
is counter to spec, but it is definitely surprising behavior.
For example, this simple C++ version of cat(1) stops catting
when it gets to a blank line:
#include <iostream>
#include <fstream>
using namespace std;
int
main(int argc, char *argv[])
{
if (argc != 2)
{
cerr << "Usage: " << argv[0] << " <file>" << endl;
exit(1);
}
ifstream file(argv[1], ios::in);
char l[255];
for (;;)
{
file.get(l, 255,'\n');
cout << "file.gcount() == " << file.gcount() << endl;
int next = file.get();
if (next == EOF)
break;
cout << l << (char)next;
}
}
--
Mark REED | CNN Internet Technology
1 CNN Center Rm SW0831G | mark.reed@cnn.com
Atlanta, GA 30348 USA | +1 404 827 4754
--
"Do you believe in intuition?"
"No, but I have a strange feeling that someday I will."