| 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 | ||||
ostrstream::ostrstream | ||||
ostrstream(); | (1) | (deprecated in C++98) (removed in C++26) |
ostrstream(char* s,int n,std::ios_base::openmode mode=std::ios_base::out); | (2) | (deprecated in C++98) (removed in C++26) |
Constructs new output strstream and its underlyingstd::strstreambuf.
strstreambuf member.app bit is not set inmode, constructs the buffer by callingstrstreambuf(s, n, s). The behavior is undefined if there are less thann elements in the array whose first element is pointed to bysapp bit is set inmode, constructs the buffer by callingstrstreambuf(s, n, s+std::strlen(s)). The behavior is undefined if there are less thann elements in the array whose first element is pointed to bys or if the array does not contain a valid null-terminated character sequence.| s | - | char array to use as the output buffer | ||||||||||||||||
| n | - | size of the array to be used as the output buffer | ||||||||||||||||
| mode | - | specifies stream open mode. It is a bitmask type, the following constants are defined (although onlyapp is used):
|
#include <iostream>#include <strstream> int main(){std::ostrstream s1;// dynamic buffer s1<<1<<' '<<3.14<<" example\n"<<std::ends;std::cout<< s1.str(); s1.freeze(false); char arr[15]="Hello"; std::ostrstream s2(arr, sizeof arr,std::ios_base::app); s2<<", world!"<<std::ends;std::cout<< s2.str()<<'\n';std::cout<< arr<<'\n';// streams use the provided arrays}
Output:
1 3.14 exampleHello, world!Hello, world!
constructs astrstreambuf object(public member function of std::strstreambuf)[edit] | |
constructs anistrstream object, optionally allocating the buffer(public member function of std::istrstream)[edit] | |
constructs astrstream object, optionally allocating the buffer(public member function of std::strstream)[edit] |