[Bug libstdc++/31456] stringstream behaves unexpectedly

pcarlini at suse dot de gcc-bugzilla@gcc.gnu.org
Tue Apr 3 08:21:00 GMT 2007



------- Comment #1 from pcarlini at suse dot de  2007-04-03 09:20 -------
(In reply to comment #0)
> the output changes to: 123de. So the initialization string gets overwritten
> instead of appending the data.

And this is the correct behavior, which you can see also in many other
implementations.

                                Inserting name.seekp(0, ios::end); helps, but
> only for compiler version 4.0, not for 4.1 (at least I think so, I couldn't
> test this enough ATM).

It helps on any recent GCC at least, gcc4.1.1, current 4.2 pre, mainline.

> Now trying to get the right behaviour by using stringstream name("abcde",
> ios::app); or stringstream name("abcde", ios::ate); leads to another
> interesting output: abcde. The input gets completely ignored.

In this case, passing only ios::app or whatelse, you are not telling at all the
stream whether you want to write or read. ios::out | ios::app works.

Really, there is nothing to fix here. One last remark: the ultimate reference
for the behavior which is implemented is the ISO C++03 Standard (+ any
implemented DR resolution), therefore always confer to it in case of doubt
about minute details, not books or manuals.


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
          Component|c++                         |libstdc++
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31456



More information about the Gcc-bugs mailing list