Condividi tramite


strstreambuf::freeze

Verrà creato un buffer del flusso a non essere disponibile con le operazioni del buffer del flusso.

void freeze( 
   bool _Freezeit = true 
);

Parametri

  • _Freezeit
    bool che indica se si desidera che il flusso da bloccare.

Note

Se _Freezeit è true, la funzione altera la modalità memorizzata di strstreambuf per eseguire la sequenza selezionata bloccata. In caso contrario, effettua la sequenza selezionata non bloccata.

str. implica freeze.

Nota

Un buffer bloccato non sarà liberato tutta la distruzione di strstreambuf.È necessario sbloccare il buffer prima che venga liberato per evitare una perdita di memoria.

Esempio

// 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);
}
  

Requisiti

strstream <diIntestazione: >

Spazio dei nomi: std

Vedere anche

Riferimenti

Classe strstreambuf

Programmazione di iostream

Convenzioni di iostream