导致流缓冲区不可用通过流缓冲区操作。
void freeze(
bool _Freezeit = true
);
参数
- _Freezeit
指示您是否为 bool 希望流冻结。
备注
如果 _Freezeit 为true,该函数修改存储的 strstreambuf 模式进行冻结的控件序列。否则,它使未冻结的控件序列。
str 提示 freeze。
![]() |
---|
冻结的缓冲区不会在 strstreambuf 损坏时被释放。它会释放避免内存泄漏之前,必须解冻缓冲区。 |
示例
// strstreambuf_freeze.cpp
// compile with: /EHsc
#include <iostream>
#include <strstream>
using namespace std;
void report(strstream &x)
{
if (!x.good())
cout << "stream bad" << endl;
else
cout << "stream good" << endl;
}
int main()
{
strstream x;
x << "test1";
cout << "before freeze: ";
report(x);
// Calling str freezes stream.
cout.write(x.rdbuf()->str(), 5) << endl;
cout << "after freeze: ";
report(x);
// Stream is bad now, wrote on frozen stream
x << "test1.5";
cout << "after write to frozen stream: ";
report(x);
// Unfreeze stream, but it is still bad
x.rdbuf()->freeze(false);
cout << "after unfreezing stream: ";
report(x);
// Clear stream
x.clear();
cout << "after clearing stream: ";
report(x);
x << "test3";
cout.write(x.rdbuf()->str(), 10) << endl;
// Clean up. Failure to unfreeze stream will cause a
// memory leak.
x.rdbuf()->freeze(false);
}
要求
标头: <strstream>
命名空间: std