Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What I can use instead of strstream::freeze?

Tags:

c++

I am working on some old c++ codes and it has strstream class which is deprecated. I need to replace them with working ones.

In my header file I got this:

ostrstream          tokenBuff;

and .c file that uses header:

tokenBuff.freeze(0);
tokenBuff.seekp(0);

I replaced ostrstream with ostringstream. ostringstream has seekp() but not freeze(). How can I deal with this problem. Thanks.

like image 916
mco Avatar asked Mar 09 '23 15:03

mco


2 Answers

You don't need freeze() in case of std::ostringstream - the necessity of calling this function was actually one of the reasons why strstream got deprecated in the first place. Because of its design (returning char* from str()) it wasn't clear who should clean the buffer that strstream holds and freeze() had to be used to signal that you want strstream itself to do it after every call to str() - in case of std::ostringstream you don't need to worry about this as str() returns a copy of the std::string.

like image 106
KjMag Avatar answered Mar 19 '23 16:03

KjMag


There is no replacement for freeze in ostringsteam since it is no longer needed. In ostrstream freeze() is used to work around the deficiency that str() returns a c-style (char *) string.

like image 41
Johan Avatar answered Mar 19 '23 17:03

Johan