This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: ostringstream not working?



+ The following program does not give the output what I'm 
+ expecting. It just writes 
+ 
+ t
+ 
+ to cout. Is it an error of me or the library (I'm using 

It's a problem in the library; ostringstream does its formatting
correctly, but currently does not expand its storage buffer.  The
single character you see is whatever happens to be the first char
written to the ostringstream.  In this respect, current ostringstreams
behave exactly like sprintf; whatever space you give it is all it has.

You can work around the problem by providing an initial string to
copy and use for a buffer:

    string          s (100, '\0');
    ostringstream   os (s);

    os << less than 100 characters worth of stuff;

(Note that the initial contents of s are overwritten, not appended to.
Opening os with ios_base::ate is also supposed to work, but currently
doesn't.  Whether it's also supposed to be the default behavior is a 
source of some discussion.)


I brought this up a few weeks ago but then everybody got swamped in
other things.  Should I start examining it some more, or is somebody
else already playing with patches?

Phil
(If you reply to the list, please don't cc another copy to me.  Thanks!)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]