making stringstream empty

Discussion in 'C++' started by mthread, Feb 21, 2008.

  1. mthread

    mthread Guest

    Hi,
    I am using a variable of type stringstream in my application. I
    am adding some information in the stream. I would like to know what is
    the method to make the stream empty. Thanx in advance.
    mthread, Feb 21, 2008
    #1
    1. Advertising

  2. mthread

    ʱ³½Î° Guest

    On 2ÔÂ21ÈÕ, ÏÂÎç5ʱ20·Ö, mthread <> wrote:
    > Hi,
    > I am using a variable of type stringstream in my application. I
    > am adding some information in the stream. I would like to know what is
    > the method to make the stream empty. Thanx in advance.


    you can use clear() method to make the stream empty.
    ʱ³½Î°, Feb 21, 2008
    #2
    1. Advertising

  3. mthread

    Guest

    On Feb 21, 2:20 pm, mthread <> wrote:
    > Hi,
    >      I am using a variable of type stringstream in my application. I
    > am adding some information in the stream. I would like to know what is
    > the method to make the stream empty. Thanx in advance.


    use str member function.

    #include <sstream>

    main()
    {
    std::stringstream sstr;
    sstr << "hello";
    sstr.str("");
    }

    Thanks,
    Balaji.
    , Feb 21, 2008
    #3
  4. In message
    <>,
    =?GB2312?B?yrGzvc6w?= <> writes
    >On 2ÔÂ21ÈÕ, ÏÂÎç5ʱ20·Ö, mthread <> wrote:
    >> Hi,
    >> I am using a variable of type stringstream in my application. I
    >> am adding some information in the stream. I would like to know what is
    >> the method to make the stream empty. Thanx in advance.

    >
    >you can use clear() method to make the stream empty.


    No, you can't. clear() clears the iostate flags. str("") makes it empty.

    --
    Richard Herring
    Richard Herring, Feb 21, 2008
    #4
  5. mthread

    Joe Greer Guest

    "=?GB2312?B?yrGzvc6w?=" <> wrote in news:ccaa3c01-
    :

    > On 2ÔÂ21ÈÕ, ÏÂÎç5ʱ20·Ö, mthread <> wrote:
    >> Hi,
    >> I am using a variable of type stringstream in my application. I
    >> am adding some information in the stream. I would like to know what is
    >> the method to make the stream empty. Thanx in advance.

    >
    > you can use clear() method to make the stream empty.


    It sure sounds like that's what it should do, doesn't it? Too bad it
    really only clears some flags. str("") is the way to reset the string.
    Joe Greer, Feb 21, 2008
    #5
  6. mthread

    Jeff Schwab Guest

    mthread wrote:
    > Hi,
    > I am using a variable of type stringstream in my application. I
    > am adding some information in the stream. I would like to know what is
    > the method to make the stream empty. Thanx in advance.


    ss.str(std::string());
    Jeff Schwab, Feb 21, 2008
    #6
    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. Replies:
    5
    Views:
    1,868
    Andrew Thompson
    Jan 12, 2005
  2. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,025
    Klaus Johannes Rusch
    Jul 16, 2003
  3. Lukas
    Replies:
    3
    Views:
    805
    spiff
    Nov 10, 2005
  4. minjie
    Replies:
    1
    Views:
    658
    Victor Bazarov
    Jul 15, 2003
  5. Francesco

    Empty a stringstream...

    Francesco, Mar 1, 2004, in forum: C++
    Replies:
    3
    Views:
    15,478
    prakasha
    Mar 22, 2011
Loading...

Share This Page