Empty a stringstream...

Discussion in 'C++' started by Francesco, Mar 1, 2004.

  1. Francesco

    Francesco Guest

    Ciao,
    I've this problem...
    #include <iostream>
    #include <stdlib.h>
    #include <sstream>
    using namespace std;
    int main(int argc, char *argv[])
    {
    stringstream s;
    s << " questa e' una prova " << endl;
    cout << s.str();
    s << " ma non so se funziona" << endl;
    cout << s.str();
    system("PAUSE");
    return 0;
    }
    The output si ...
    questa e' una prova
    questa e' una prova
    ma non so se funziona
    Premere un tasto per continuare...

    But I want...
    questa e' una prova
    ma non so se funziona
    Premere un tasto per continuare...


    How may I delete the old value in the stream and use the stringstream in
    rewrite mode and not in append?
    Grazie mille,
    Checco.
    Francesco, Mar 1, 2004
    #1
    1. Advertising

  2. Francesco

    Rolf Magnus Guest

    Francesco wrote:

    > Ciao,
    > I've this problem...
    > #include <iostream>
    > #include <stdlib.h>
    > #include <sstream>
    > using namespace std;
    > int main(int argc, char *argv[])
    > {
    > stringstream s;
    > s << " questa e' una prova " << endl;
    > cout << s.str();
    > s << " ma non so se funziona" << endl;
    > cout << s.str();
    > system("PAUSE");
    > return 0;
    > }
    > The output si ...
    > questa e' una prova
    > questa e' una prova
    > ma non so se funziona
    > Premere un tasto per continuare...
    >
    > But I want...
    > questa e' una prova
    > ma non so se funziona
    > Premere un tasto per continuare...
    >
    >
    > How may I delete the old value in the stream and use the stringstream
    > in rewrite mode and not in append?


    There is no such thing as "rewrite mode". How would the stream know as
    which points you want them to erase their content? You can however
    empty them explicitly by doing:

    s.str("");
    Rolf Magnus, Mar 1, 2004
    #2
    1. Advertising

  3. Francesco

    Francesco Guest

    On Mon, 01 Mar 2004 12:03:01 +0100, Rolf Magnus <>
    wrote:

    >
    > There is no such thing as "rewrite mode". How would the stream know as
    > which points you want them to erase their content? You can however
    > empty them explicitly by doing:
    >
    > s.str("");
    >
    >


    Thanks... it's exactly what I need.

    Thanks again,
    Checco.
    Francesco, Mar 1, 2004
    #3
  4. Francesco

    prakasha

    Joined:
    Mar 22, 2011
    Messages:
    2
    Thanks alot.... Rolf Magnus :)
    prakasha, Mar 22, 2011
    #4
    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. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,022
    Klaus Johannes Rusch
    Jul 16, 2003
  2. Lukas
    Replies:
    3
    Views:
    802
    spiff
    Nov 10, 2005
  3. minjie
    Replies:
    1
    Views:
    656
    Victor Bazarov
    Jul 15, 2003
  4. Marcia Hon

    Check if a directory is empty and empty it

    Marcia Hon, Feb 8, 2004, in forum: C Programming
    Replies:
    8
    Views:
    572
    Dave Thompson
    Feb 14, 2004
  5. mthread

    making stringstream empty

    mthread, Feb 21, 2008, in forum: C++
    Replies:
    5
    Views:
    1,796
    Jeff Schwab
    Feb 21, 2008
Loading...

Share This Page