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. Advertisements

  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. Advertisements

  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. Advertisements

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. Alex Vinokur

    vector of ostringstream

    Alex Vinokur, Jul 10, 2003, in forum: C++
    Replies:
    4
    Views:
    1,005
    llewelly
    Jul 14, 2003
  2. Mark Warren
    Replies:
    3
    Views:
    16,923
    Sam Holden
    Jul 23, 2003
  3. Mike
    Replies:
    1
    Views:
    1,325
    John Harrison
    Aug 3, 2003
  4. James Madison

    ostringstream

    James Madison, Aug 5, 2003, in forum: C++
    Replies:
    2
    Views:
    570
    Grzegorz Sakrejda
    Aug 5, 2003
  5. Eric Boutin
    Replies:
    6
    Views:
    7,933
    Dan W.
    Dec 3, 2003
  6. jay
    Replies:
    4
    Views:
    3,480
  7. Replies:
    6
    Views:
    941
    Marcus Kwok
    Jan 10, 2006
  8. Aman JIANG

    a question about ostringstream

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