Firt of all i would like to let all know that ostrstream is deprecated and it should not be used in future.
but my doubt is something else. the source code of my application has code like below.
ostrstream o;
o << cell.value(CI) << "-" << cell.value(LAC) << "-" << cell.value(MNC)
<< "-" << cell.value(MCC) << ends;
char* tmp = o.str();
cgi = tmp;
delete [] tmp;
the line of code which is of my interest is the last line. do we have to delete a pointer in this case.this looks quite awkward to me. there is no memory allocation manually.am i thinking in the right way?
The pointer is still owned by the ostrstream
. Deallocating it is in error.
It may be correct if the documentation for ostrstream::str()
said that ownership is transferred, in this case, str()
would serve as an allocation function.