ostringstream Question

M

Mike Copeland

How can I clear/reset/initialize an ostringstream object? I've tried
both clear() and flush() calls to reset an object I've used (so that I
can reuse it), but neither works: subsequent uses only append to the
object. Please advise. TIA
 
B

Bo Persson

Mike Copeland skrev 2013-05-01 01:49:
How can I clear/reset/initialize an ostringstream object? I've tried
both clear() and flush() calls to reset an object I've used (so that I
can reuse it), but neither works: subsequent uses only append to the
object. Please advise. TIA

If you want EVERYTHING back to the default settings, it is actually
cheapest to create a new stringstream. There are LOTS of settings in a
stream object.


Bo Persson
 
B

Bo Persson

Mike Copeland skrev 2013-05-02 18:54:
Yes, but that's not what I'm trying: I wish to reuse an ostringstream
several times within a subprogram. Inasmuch as I'm constructing several
large streams, I don't think it's a good idea to instantiate more than 1
such object in a subprogram. Am I wrong about this, Heap and
performance-wise? TIA

It probably doesn't matter much.

What I'm saying is that if you use many settings for the stream (fill,
hex, left, uppercase, boolalpha, showbase, etc, etc), it is more
efficient to create a new stream than to try to reset all of those to
their default values.



Bo Persson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,800
Messages
2,569,657
Members
45,417
Latest member
BonitaNile
Top