Search code examples
c++c++11ostringstreamstrstream

basic_stringbuf has no member named 'freeze'


The following code fails to compile:

#include <cstdio> 
#include <sstream>
int main()
{
   std::ostrstream strm;                         
   strm.rdbuf()->freeze(0);                      
}

I get the following errors on compilation:

g++ sample3.cpp
sample3.cpp: In function 'int main()':
sample3.cpp:5: error: 'ostrstream' is not a member of 'std'
sample3.cpp:5: error: expected `;' before 'strm'
sample3.cpp:6: error: 'strm' was not declared in this scope

After searching in google, I suspect that I should use ostringstream in place of ostrstream, so I have modified the program as below:

#include <cstdio> 
#include <sstream>
int main()
{
   std::ostringstream strm;                         
   strm.rdbuf()->freeze(0);                      
}

But now I get the following errors:

g++ sample3.cpp
sample3.cpp: In function 'int main()':
sample3.cpp:6: error: 'struct std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >' has no member named 'freeze'

Solution

  • Just scrap the freeze() call -- the current generation std::ostringstream doesn't expose its memory management guts to you like the old ostrstream did. You'll need to rework your original code to let the stringstream manage memory in the way it wants (it'll be much simpler/less error-prone that way!).