| 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) |
| Public member functions | ||||
strstreambuf::str | ||||
| Protected member functions | ||||
char* str(); | (deprecated in C++98) (removed in C++26) | |
Callsfreeze(), then returns a copy of start pointer of the get area,std::streambuf::eback().
The start of the get area, for all writeablestd::strstreambuf objects constructed through the interface provided bystd::strstream, is also the start of the put area.
Contents |
(none)
A copy ofeback(), which may be a null pointer.
This function is typically called through thestd::strstream interface.
The call tofreeze() guarantees that the returned pointer remains valid until the next explicit call tofreeze(false): otherwise (on a dynamic buffer) any output operation could trigger buffer reallocation which would invalidate the pointer. It also causes a memory leak in the destructor ofstd::strstreambuf, unlessfreeze(false) is called before the buffer (or, more commonly, thestd::strstream that manages it) is destroyed.
#include <iostream>#include <strstream> int main(){std::strstream dyn;// dynamically-allocated read/write buffer dyn<<"Test: "<<1.23<<std::ends;std::strstreambuf* buf= dyn.rdbuf();std::cout<<"R/W buffer holds ["<< buf->str()// or dyn.str()<<"]\n"; dyn.freeze(false);// after calling .str() on a dynamic strstream char arr[10];std::ostrstream user(arr,10);// fixed-size write-only buffer buf= user.rdbuf(); user<<1.23<<std::ends;std::cout<<"Write-only buffer holds ["<< buf->str()// or user.str()<<"]\n"; std::istrstream lit("1 2 3");// fixed-size read-only buffer buf= lit.rdbuf();std::cout<<"Read-only buffer holds ["<< buf->str()// or lit.str()<<"]\n";}
Output:
R/W buffer holds [Test: 1.23]Write-only buffer holds [1.23]Read-only buffer holds [1 2 31 2 3]
| accesses the output buffer (public member function of std::strstream)[edit] | |
| accesses the output buffer (public member function of std::ostrstream)[edit] | |
| accesses the output buffer (public member function of std::istrstream)[edit] |