| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Member functions | ||||
strstream::freeze |
void freeze(bool flag=true); | (deprecated in C++98) (removed in C++26) | |
If the stream is using a dynamically-allocated array for output, disables (flag==true) or enables (flag==false) automatic allocation/deallocation of the buffer. Effectively callsrdbuf()->freeze(flag).
Contents |
After a call tostr(), dynamic streams become frozen automatically. A call tofreeze(false) is required before exiting the scope in which thisstrstream object was created, otherwise the destructor will leak memory. Also, additional output to a frozen stream may be truncated once it reaches the end of the allocated buffer.
| flag | - | desired status |
(none)
#include <iostream>#include <strstream> int main(){std::strstream dyn;// dynamically-allocated output buffer dyn<<"Test: "<<1.23;// note: no std::ends to demonstrate appendingstd::cout<<"The output stream contains\"";std::cout.write(dyn.str(), dyn.pcount())<<"\"\n";// the stream is now frozen due to str() dyn<<" More text";// output to a frozen stream may be truncatedstd::cout<<"The output stream contains\"";std::cout.write(dyn.str(), dyn.pcount())<<"\"\n"; dyn.freeze(false);// freeze(false) must be called or the destructor will leak std::strstream dyn2;// dynamically-allocated output buffer dyn2<<"Test: "<<1.23;// note: no std::endsstd::cout<<"The output stream contains\"";std::cout.write(dyn2.str(), dyn2.pcount())<<"\"\n"; dyn2.freeze(false);// unfreeze the stream after str() dyn2<<" More text"<<std::ends;// output will not be truncated (buffer grows)std::cout<<"The output stream contains\""<< dyn2.str()<<"\"\n"; dyn2.freeze(false);// freeze(false) must be called or the destructor will leak}
Possible output:
The output stream contains "Test: 1.23"The output stream contains "Test: 1.23 More "The output stream contains "Test: 1.23"The output stream contains "Test: 1.23 More text"
| sets/clears the frozen state of the buffer (public member function of std::strstreambuf)[edit] |