Hey guys, I was wondering if the stringstream class copied the string to itself or just keeps a pointer.

Because if it copies I can free or clear the string without fearing for the data in stringstream.


Like this:

string stringz0r("Chickenz");
stringstream streamz0r(stringz0r);
//will this not affect the stringstream in any way?

Or, maybe a bit more complicated:

string *stringz0r = new string("Chickenz");
stringstream *streamz0r = new stringstream(*stringz0r);
//will this...
delete stringz0r;

Thanks in advance,

It makes a copy of the string. For it not to do so would be counter-intuitive -- if it wanted a pointer to a string, it would ask for one.

In particular, you'll note that the constructor takes a const string. Which means that there's no way in heck that the stringstream could use the string it receives for its internal buffer.

Ah yes, of course, thanks a bunch. I'll take a look at the ctor next time such a question pops into my mind.

This question has already been answered. Start a new discussion instead.