basic_stringbuf 没有名为 'freeze' 的成员

basic_stringbuf has no member named 'freeze'

以下代码编译失败:

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

编译时出现以下错误:

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

在google中搜索后,我怀疑我应该用ostringstream代替ostrstream,所以我修改了程序如下:

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

但现在我得到以下错误:

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'

只需取消 freeze() 调用——当前一代 std::ostringstream 不会像旧 ostrstream 那样向您公开其内存管理功能。您需要重新编写原始代码,让 stringstream 按照它想要的方式管理内存(那样会 simpler/less 容易出错!)。

我应该把 #include "sstream" 改成 #include "strstream" 那么就不会报错“'ostrstream' is not member of 'std'”.