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.

EDIT:

Like this:

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

Or, maybe a bit more complicated:

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

Thanks in advance,
Nick

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.