strstreambuf::freeze
导致流缓冲区不可通过流缓冲区操作。
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