Topic: Bug in operator<<(ostream, string) ?
Author: sorry@but.spammed.out (Howard Hinnant)
Date: 1998/03/11 Raw View
Hi,
Is there a bug in operator<<ostream, string) or have I just lost my
ability to read straight? The standard says:
<quote>
Effects:
Begins by constructing a sentry object k as if k were constructed by
typename basic_ostream<charT,traits>::sentry k(os). If bool(k) is
true, inserts characters as if by calling
os.rdbuf()->sputn(str.data(), n), padding as described in stage 3 of
_lib.facet.num.put.virtuals_, where n is the smaller of os.width()
and str.size(); then calls os.width(0). If the call to sputn fails,
calls os.setstate(ios_base::failbit).
<end quote>
My problem is with the definition of 'n' (the number of characters to be
printed). If n is the smaller of os.width() and str.size(), doesn't that
mean that the default width (which is 0) inhibits the printing of string
completely?!!
string a("Hi");
cout << a; // Prints nothing!
Perhaps the intent was to say "n is the greater of os.width() and
str.size()". Then all that verbage regarding padding would actually be
relevant.
Comments?
-Howard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]