This is the mail archive of the
libstdc++@sources.redhat.com
mailing list for the libstdc++ project.
Re: [bug] istream::getline(char*,streamsize) still broken
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: Re: [bug] istream::getline(char*,streamsize) still broken
- From: Benjamin Kosnik <bkoz at redhat dot com>
- Date: Sat, 22 Jul 2000 12:09:29 -0700
Brent:
I'm ready to concede. I've looked at existing practice and scoped the
reflector archives. It was my contention that after n - 1 characters
were extracted (ie, after 'd' in "abcd") that no more characters were
extracted, period.
We are/were both in agreement about what gcount() returns.
This seems to be wrong. Here's what should happen (I'm hoping we can
now easily agree on this:)
#include <cstring>
#include <istream>
#include <sstream>
// http://sources.redhat.com/ml/libstdc++/2000-07/msg00126.html
int
main()
{
using namespace std;
bool test = true;
const streamsize it = 5;
char tmp[it];
const char* str_lit = "abcd\n";
stringbuf strbuf(str_lit, std::ios_base::in);
istream istr(&strbuf);
istr.getline(tmp,it);
test &= istr.gcount() == it; // extracted whole string
test &= strlen(tmp) == 4; // stored all but '\n'
test &= !istr.eof(); // extracted up to but not eof
test &= !istr.fail(); // failbit not set
char c = 'z';
istr.get(c);
test &= c == 'z';
test &= istr.eof();
return 0;
}
If you can re-submit your patch reflective of this, patch up any
testcase weirdness and add the above, that would be cool.
thanks,
benjamin