std::ostrstream(3)
π std::ostrstream π β like, the C++ Standard Library one, bestie (page std::ostrstream(3), C++ Standard Libary, std::ostrstream(3))
Ok so listen. This is std::ostrstream, and no I'm not gonna pretend it's still that girl β it's deprecated and honestly kind of a legacy icon. But we're gonna learn it anyway because your girl does not skip content. Periodt. π
β¨ NAME β¨
std::ostrstream β literally std::ostrstream. That's the name. That's the whole thing. π
π¦ Synopsis π¦
First of all, where does it live:
Defined in header <strstream>
And here's the class, exactly as it is:
class ostrstream : public std::ostream (deprecated in C++98)
(removed in C++26)
So real talk: the class ostrstream implements output operations on array-backed streams. Basically it wraps a raw array I/O device implementation (std::strstreambuf) into the higher-level interface of std::basic_ostream. It's giving "glow-up wrapper" energy β¨
And the typical implementation of ostrstream holds only one non-derived data member: an object of type std::strstreambuf. One. Single. Member. Minimalist queen π«Ά
πΈ Notes πΈ
Okay these notes are important, do not scroll past:
- After any call to
str(), a call tofreeze(false)is required to allow the destructor to deallocate the buffer as necessary. So like, don't forget thefreeze(false)or your destructor can't do its job π - Before any call to
str()that uses the result as a C-string, the buffer must be null-terminated, typically withstd::ends. Get that terminating vibe in there first, iykyk. ostrstreamhas been deprecated since C++98 and removed since C++26. Yeah. It's been over for a minute. π- The recommended replacements are
std::ostringstream,std::ospanstream(since C++23), andboost::iostreams::array_sink. Those are the ones eating in 2023+ and beyond. π
Bestie note: the "deprecated since C++98, removed since C++26" thing is not a drill. If you're reaching for this in new code, maybe⦠don't? The replacements above are right there.
π₯ Member functions π₯
The main character lineup, all public members:
- constructor β constructs an
ostrstreamobject, optionally allocating the buffer (public member function) - destructor β destructs an
ostrstreamobject, optionally deallocating the buffer, and it's marked[virtual](virtual public member function) - rdbuf β obtains a pointer to the associated
strstreambuf(public member function) - str β accesses the output buffer (public member function)
- freeze β disables/enables automatic reallocation (public member function)
- pcount β obtains the number of characters written (public member function)
π Inherited from std::basic_ostream π
Yeah she inherited all of this. Generous ancestor. π
π Member functions π
π Formatted output
operator<<β inserts formatted data (public member function ofstd::basic_ostream<CharT,Traits>)
π« Unformatted output
putβ inserts a character (public member function ofstd::basic_ostream<CharT,Traits>)writeβ inserts blocks of characters (public member function ofstd::basic_ostream<CharT,Traits>)
β Positioning
tellpβ returns the output position indicator (public member function ofstd::basic_ostream<CharT,Traits>)seekpβ sets the output position indicator (public member function ofstd::basic_ostream<CharT,Traits>)
π¦ Miscellaneous
flushβ synchronizes with the underlying storage device (public member function ofstd::basic_ostream<CharT,Traits>)
π Member classes
sentryβ implements basic logic for preparation of the stream for output operations (public member class ofstd::basic_ostream<CharT,Traits>)
π§ Inherited from std::basic_ios π§
More inheritance, more slay. π
π Member types
Here's the whole mapping, one bullet per type because tables are not the vibe in this terminal:
char_typeβCharTtraits_typeβTraitsint_typeβTraits::int_typepos_typeβTraits::pos_typeoff_typeβTraits::off_type
πΈ Member functions πΈ
π State functions
goodβ checks if no error has occurred i.e. I/O operations are available (public member function ofstd::basic_ios<CharT,Traits>)eofβ checks if end-of-file has been reached (public member function ofstd::basic_ios<CharT,Traits>)failβ checks if an error has occurred (public member function ofstd::basic_ios<CharT,Traits>)badβ checks if a non-recoverable error has occurred (public member function ofstd::basic_ios<CharT,Traits>)operator!β checks if an error has occurred (synonym offail()) (public member function ofstd::basic_ios<CharT,Traits>)operator boolβ checks if no error has occurred (synonym of!fail()) (public member function ofstd::basic_ios<CharT,Traits>)rdstateβ returns state flags (public member function ofstd::basic_ios<CharT,Traits>)setstateβ sets state flags (public member function ofstd::basic_ios<CharT,Traits>)clearβ modifies state flags (public member function ofstd::basic_ios<CharT,Traits>)
π Formatting
copyfmtβ copies formatting information (public member function ofstd::basic_ios<CharT,Traits>)fillβ manages the fill character (public member function ofstd::basic_ios<CharT,Traits>)
π Miscellaneous
exceptionsβ manages exception mask (public member function ofstd::basic_ios<CharT,Traits>)imbueβ sets the locale (public member function ofstd::basic_ios<CharT,Traits>)rdbufβ manages associated stream buffer (public member function ofstd::basic_ios<CharT,Traits>)tieβ manages tied stream (public member function ofstd::basic_ios<CharT,Traits>)narrowβ narrows characters (public member function ofstd::basic_ios<CharT,Traits>)widenβ widens characters (public member function ofstd::basic_ios<CharT,Traits>)
π Inherited from std::ios_base π
The OG base class. Everything trickles down from here, bestie. π«Ά
π Member functions π
β¨ Formatting
flagsβ manages format flags (public member function ofstd::ios_base)setfβ sets specific format flag (public member function ofstd::ios_base)unsetfβ clears specific format flag (public member function ofstd::ios_base)precisionβ manages decimal precision of floating point operations (public member function ofstd::ios_base)widthβ manages field width (public member function ofstd::ios_base)
π Locales
imbueβ sets locale (public member function ofstd::ios_base)getlocβ returns current locale (public member function ofstd::ios_base)
ποΈ Internal extensible array
xallocβ returns a program-wide unique integer that is safe to use as index topword()andiword(), and it's marked[static](public static member function ofstd::ios_base)iwordβ resizes the private storage if necessary and access to thelongelement at the given index (public member function ofstd::ios_base)pwordβ resizes the private storage if necessary and access to thevoid*element at the given index (public member function ofstd::ios_base)
π¦ Miscellaneous
register_callbackβ registers event callback function (public member function ofstd::ios_base)sync_with_stdioβ sets whether C++ and C I/O libraries are interoperable, and it's marked[static](public static member function ofstd::ios_base)
π Member classes
failureβ stream exception (public member class ofstd::ios_base)Initβ initializes standard stream objects (public member class ofstd::ios_base)
β¨ Member types and constants β¨
Okay bestie, this is the type-and-constant cheat sheet π β every single name stays exactly as written, no cap. Letβs go.
πΈ stream open mode type
openmode β (typedef)
The following constants are also defined:
appβ seek to the end of stream before each writebinaryβ open in binary modeinβ open for readingoutβ open for writingtruncβ discard the contents of the stream when openingateβ seek to the end of stream immediately after opennoreplace(C++23) β open in exclusive mode
π formatting flags type
fmtflags β (typedef)
The following constants are also defined:
decβ use decimal base for integer I/O: seestd::decoctβ use octal base for integer I/O: seestd::octhexβ use hexadecimal base for integer I/O: seestd::hexbasefieldβdec|oct|hex. Useful for masking operationsleftβ left adjustment (adds fill characters to the right): seestd::leftrightβ right adjustment (adds fill characters to the left): seestd::rightinternalβ internal adjustment (adds fill characters to the internal designated point): seestd::internaladjustfieldβleft|right|internal. Useful for masking operationsscientificβ generate floating point types using scientific notation, or hex notation if combined withfixed: seestd::scientificfixedβ generate floating point types using fixed notation, or hex notation if combined withscientific: seestd::fixedfloatfieldβscientific|fixed. Useful for masking operationsboolalphaβ insert and extractbooltype in alphanumeric format: seestd::boolalphashowbaseβ generate a prefix indicating the numeric base for integer output, require the currency indicator in monetary I/O: seestd::showbaseshowpointβ generate a decimal-point character unconditionally for floating-point number output: seestd::showpointshowposβ generate a+character for non-negative numeric output: seestd::showposskipwsβ skip leading whitespace before certain input operations: seestd::skipwsunitbufβ flush the output after each output operation: seestd::unitbufuppercaseβ replace certain lowercase letters with their uppercase equivalents in certain output operations: seestd::uppercase
π state of the stream type
iostate β (typedef)
The following constants are also defined:
goodbitβ no errorbadbitβ irrecoverable stream errorfailbitβ input/output operation failed (formatting or extraction error)eofbitβ associated input sequence has reached end-of-file
π¦ seeking direction type
seekdir β (typedef)
The following constants are also defined:
begβ the beginning of a streamendβ the ending of a streamcurβ the current position of stream position indicator
π event things
eventβ(enum)β specifies event typeevent_callbackβ(typedef)β callback function type
Thatβs the whole list, bestie β every type, every constant, every little (typedef) and (enum) accounted for π. This page came from http://cppreference.com, dated 2024.06.10, and itβs the std::ostrstream(3) page π.
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms