Thread: stringstream

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    42

    stringstream

    I created a stringstream but I don't know how to clear the memory.
    Example

    Code:
    stringstream sstring;
    int a = 12;
    int b = 14;
    
    sstring << a;
    cout << sstring.str();
    I get 12;

    Code:
    sstring << b;
    cout << sstring.str();
    I will get 1214. But I want 14. I tried sstring.flush(), but it did not work. Could someone please help out? Thanks in advance.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Code:
    sstring.str("");
    If you're doing it in a loop, just declare the stringstream inside the loop instead.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    42
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stringstream problem
    By black_spot1984 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 04:09 PM
  2. stringstream clear
    By misterowakka in forum C++ Programming
    Replies: 3
    Last Post: 01-01-2008, 01:03 PM
  3. Socket: send stringstream
    By crisis in forum C++ Programming
    Replies: 5
    Last Post: 11-22-2007, 10:50 AM
  4. Length of a stringstream
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 10-24-2003, 07:30 PM
  5. Flushing a stringstream
    By Eibro_Guest in forum C++ Programming
    Replies: 1
    Last Post: 01-06-2003, 03:21 PM