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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With