We help IT Professionals succeed at work.

reset a stringstream

bormuth
bormuth asked
on

Is it possible to reset a stringstream so that it is empty afterwards.

   stringstream s;
   s << "Hello";
   s.reset();           // <-- HOW TO DO THIS
   std::cout s.str();   // <-- Should print NOTHING


(Even s = stringstream() doesn't work).
Comment
Watch Question

AxterSenior Software Engineer

Commented:
Try s = stringstream("");

Example:
int main()
{
     stringstream s;
     s << "Hello";
     s = stringstream("");
     std::cout << s.str();   // <-- Should print NOTHING
     return 0;
}

Author

Commented:

Axter:

There is no asignment operator for stringstream...


Error E2285: Could not find a match for 'stringstream::operator =(stringstream)'
AxterSenior Software Engineer

Commented:
What compiler are you using?

Author

Commented:

Borland C++ 5.5.1 for Win32
AxterSenior Software Engineer

Commented:
>>There is no asignment operator for stringstream...

There is an assignment operator in VC++.
You can use s.str(""); Here is the code

#include <iostream>
#include <sstream>
using namespace std;


void main()
{
    stringstream s;
    s << "Hello";

    s.str("");  <------ the code you need


    std::cout << s.str() << endl;   // <-- Should print NOTHING
}

Author

Commented:


Yea ... that's great !!!

           Thanks ....