ostringstream Question

Discussion in 'C++' started by Mike Copeland, May 1, 2013.

  1. 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
    Mike Copeland, May 1, 2013
    #1
    1. Advertising

  2. Mike Copeland

    Bo Persson Guest

    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
    Bo Persson, May 1, 2013
    #2
    1. Advertising

  3. Mike Copeland

    Bo Persson Guest

    Mike Copeland skrev 2013-05-02 18:54:
    > In article <>, says...
    >>> 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.
    >>

    >
    > 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
    Bo Persson, May 2, 2013
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Victor Bazarov
    Replies:
    0
    Views:
    844
    Victor Bazarov
    Jun 25, 2003
  2. Russell Hanneken
    Replies:
    0
    Views:
    889
    Russell Hanneken
    Jun 25, 2003
  3. Alex Vinokur

    vector of ostringstream

    Alex Vinokur, Jul 10, 2003, in forum: C++
    Replies:
    4
    Views:
    690
    llewelly
    Jul 14, 2003
  4. Replies:
    6
    Views:
    834
    Marcus Kwok
    Jan 10, 2006
  5. Aman JIANG

    a question about ostringstream

    Aman JIANG, Sep 18, 2007, in forum: C++
    Replies:
    0
    Views:
    320
    Aman JIANG
    Sep 18, 2007
Loading...

Share This Page