The first form (1) returns a string object with a copy of the current contents in the stream buffer.

The second form (2) sets str as the contents of the stream buffer, discarding any previous contents. The object preserves its open mode: if this includes ios_base::ate, the put pointer (pptr) is moved to the end of the new sequence.