Post by Victor BazarovMaybe there is a defect in the Standard, or a defect in Dinkumware's
implementation (based on their interpretation). What would be the
[observable] difference between calling 'sputn' and 'sputc'
(repeatedly)? I'm guessing you need your virtual function called (as
specified in the behaviour of 'sputn')
sputn() indeed calls xsputn() and the latter can be overridden in a derived
class. The idea was optimisation: rather than calling sputc() to write one
character at a time potentially with checks on each output, you can call
sputn() to write more than one character in one go. I further noticed that if
it makes sense, the buffer in a class derived from std::streambuf can be
completely dispensed with, so rather than writing to the buffer as temporary
storage, you can send characters to the ultimate destination without copying.
Post by Victor BazarovIf you think it's a defect in the implementation, contact Dinkumware or
Microsoft and see what they have to say about that. If you think it's a
defect in the Standard (and the expected wording needs to be stronger),
post to 'comp.std.c++'.
I think it is a defect in the implementation but, based on past experience,
I seriously doubt Microsoft will do anything about it.
Post by Victor BazarovIs there a different approach available to you? 'sputc' is specified to
check the availability of the room in the buffer using the pointers
(xnext and xend), and call 'overflow' where you're supposed to dump the
characters (send or whatever), and change the pointers (not sure what
the right code is). What book are you reading, BTW? I remember hearing
that Angelika Langer's "Standard C++ Iostreams" was very good. Also,
Josuttis' C++ Standard Library book is highly praised.
The workaround seems to be to call sputn() directly, so instead of
extern std::ostream& os;
os << std::string(255, 'a');
I can write
extern std::ostream& os;
const std::string s(255, 'a');
os.rdbuf()->sputn(s.data(), s.size());
I do not like Angelika Langer or Josuttis (I have the former book), if
forgivable (thank you for the recommendation: this is not in any way to
detract from it). I like Steve Teale's book on classic iostreams and
Plauger's Draft C++ Standard, even if outdated.