std::strstream(3)
Welcome to std::strstream(3) from the C++ Standard Library, bestie β sheβs serving deprecated-era main character energy π
π NAME π
std::strstream - std::strstream. Thatβs the name, no cap. Sheβs a class, and sheβs here to do array-backed input/output things. She ate.
β¨ Synopsis β¨
Defined in header <strstream>
class strstream : public std::iostream (deprecated in C++98)
(removed in C++26)
Okay so the class strstream implements input and output operations on array-backed streams. The way that works is it essentially wraps a raw array I/O device implementation (std::strstreambuf) into the higher-level interface of std::basic_iostream. Obsessed with the layering.
The typical implementation of strstream holds only one non-derived data member: an object of type std::strstreambuf. Thatβs it. One data member. Lowkey elegant.
π Notes π
After any call to str(), a call to freeze(false) is required to allow the destructor to deallocate the buffer as necessary. Like, literally required. Donβt skip it, fr fr.
Before any call to str() that uses the result as a C-string, the buffer must be null-terminated, typically with std::ends.
π¨ Vibe check:strstreamhas been deprecated since C++98 and removed since C++26.std::stringstream,std::spanstream(since C++23), andboost::iostreams::arrayare the recommended replacements. So yes, sheβs iconic, but sheβs highkey a legacy situation. Itβs giving legacy, iykyk. Slay, but deprecated. Periodt. Not me getting emotional about a removed stream class π
π Member functions π
constructorβ constructs astrstreamobject, optionally allocating the buffer (public member function).destructorβ destructs astrstreamobject, optionally deallocating the buffer.[virtual](virtual public member function).rdbufβ obtains a pointer to the associatedstrstreambuf(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_istream π
Member functions
Formatted input
operator>>β extracts formatted data (public member function ofstd::basic_istream<CharT,Traits>).
Unformatted input
getβ extracts characters (public member function ofstd::basic_istream<CharT,Traits>).peekβ reads the next character without extracting it (public member function ofstd::basic_istream<CharT,Traits>).ungetβ unextracts a character (public member function ofstd::basic_istream<CharT,Traits>).putbackβ puts a character into input stream (public member function ofstd::basic_istream<CharT,Traits>).getlineβ extracts characters until the given character is found (public member function ofstd::basic_istream<CharT,Traits>).ignoreβ extracts and discards characters until the given character is found (public member function ofstd::basic_istream<CharT,Traits>).readβ extracts blocks of characters (public member function ofstd::basic_istream<CharT,Traits>).readsomeβ extracts already available blocks of characters (public member function ofstd::basic_istream<CharT,Traits>).gcountβ returns number of characters extracted by last unformatted input operation (public member function ofstd::basic_istream<CharT,Traits>).
Positioning
tellgβ returns the input position indicator (public member function ofstd::basic_istream<CharT,Traits>).seekgβ sets the input position indicator (public member function ofstd::basic_istream<CharT,Traits>).
Miscellaneous
syncβ synchronizes with the underlying storage device (public member function ofstd::basic_istream<CharT,Traits>).
Member classes
sentryβ implements basic logic for preparation of the stream for input operations (public member class ofstd::basic_istream<CharT,Traits>).
πΈ Inherited from std::basic_ostream πΈ
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>).
β¨ Member types and constants β¨
okay so first up, the type menu. Itβs giving βtypedef and enum family reunion,β and every one of these is literally listed on the page:
openmodeβ stream open mode type (typedef)fmtflagsβ formatting flags type (typedef)iostateβ state of the stream type (typedef)seekdirβ seeking direction type (typedef)eventβ specifies event type (enum)event_callbackβ callback function type (typedef)
π§ openmode β stream open mode type (typedef)
The following constants are also defined, bestie:
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
π fmtflags β formatting flags type (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
πΈ iostate β state of the stream type (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
π¦ seekdir β seeking direction type (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
β the last two types, no cap
eventβ specifies event type (enum)event_callbackβ callback function type (typedef)
thatβs the whole vibe check, bestie: source http://cppreference.com, version/date 2024.06.10, and the page is std::strstream(3) π
β¨
π¦ 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