|
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 calls rdbuf()->freeze(flag)
.
Notes
After a call to str()
, dynamic streams become frozen automatically. A call to freeze(false)
is required before exiting the scope in which this strstream
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.
Parameters
flag | - | desired status |
Return value
(none).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <strstream> #include <iostream> int main() { std::strstream dyn; // dynamically-allocated output buffer dyn << "Test: " << 1.23; std::cout << "The output stream contains \"" << dyn.str() << "\"\n" ; // the stream is now frozen due to str() dyn << " More text" ; // output to a frozen stream may be truncated std::cout << "The output stream contains \"" << dyn.str() << "\"\n\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; std::cout << "The output stream contains \"" << dyn2.str() << "\"\n" ; dyn2.freeze( false ); // unfreeze the stream after str() dyn2 << " More text" ; // output will not be truncated (the underlying buffer may grow) std::cout << "The output stream contains \"" << dyn2.str() << "\"\n" ; dyn2.freeze( false ); // freeze(false) must be called or the destructor will leak } |
Possible output:
1 2 3 4 5 | 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" |
See also
sets/clears the frozen state of the buffer (public member function of std::strstreambuf ) |
Please login to continue.