strstreambuf::freeze

會將資料流緩衝區無法使用經由資料流緩衝區作業。

void freeze(
   bool _Freezeit = true
);

參數

  • _Freezeit
    指出您是否要 bool 資料流凍結。

備註

如果 _Freezeit 為 true 時,函式修改預存 strstreambuf 模式進行凍結的受控制序列。否則,將不凍結的受控制序列。

str 隱含 freeze

注意事項注意事項

凍結的緩衝區不會在 strstreambuf 解構期間釋放。,會釋放避免記憶體遺漏 (Memory Leak) 之前,您必須先解除凍結緩衝區。

範例

// 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

請參閱

參考

strstreambuf Class

iostream 程式設計

iostreams 慣例