std::strstream(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

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: strstream has been deprecated since C++98 and removed since C++26. std::stringstream, std::spanstream (since C++23), and boost::iostreams::array are 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 a strstream object, optionally allocating the buffer (public member function).
  • destructor β€” destructs a strstream object, optionally deallocating the buffer. [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_istream 🌈

Member functions

Formatted input

  • operator>> β€” extracts formatted data (public member function of std::basic_istream<CharT,Traits>).

Unformatted input

  • get β€” extracts characters (public member function of std::basic_istream<CharT,Traits>).
  • peek β€” reads the next character without extracting it (public member function of std::basic_istream<CharT,Traits>).
  • unget β€” unextracts a character (public member function of std::basic_istream<CharT,Traits>).
  • putback β€” puts a character into input stream (public member function of std::basic_istream<CharT,Traits>).
  • getline β€” extracts characters until the given character is found (public member function of std::basic_istream<CharT,Traits>).
  • ignore β€” extracts and discards characters until the given character is found (public member function of std::basic_istream<CharT,Traits>).
  • read β€” extracts blocks of characters (public member function of std::basic_istream<CharT,Traits>).
  • readsome β€” extracts already available blocks of characters (public member function of std::basic_istream<CharT,Traits>).
  • gcount β€” returns number of characters extracted by last unformatted input operation (public member function of std::basic_istream<CharT,Traits>).

Positioning

  • tellg β€” returns the input position indicator (public member function of std::basic_istream<CharT,Traits>).
  • seekg β€” sets the input position indicator (public member function of std::basic_istream<CharT,Traits>).

Miscellaneous

  • sync β€” synchronizes with the underlying storage device (public member function of std::basic_istream<CharT,Traits>).

Member classes

  • sentry β€” implements basic logic for preparation of the stream for input operations (public member class of std::basic_istream<CharT,Traits>).

🌸 Inherited from std::basic_ostream 🌸

Member functions

Formatted output

  • operator<< β€” inserts formatted data (public member function of std::basic_ostream<CharT,Traits>).

Unformatted output

  • put β€” inserts a character (public member function of std::basic_ostream<CharT,Traits>).
  • write β€” inserts blocks of characters (public member function of std::basic_ostream<CharT,Traits>).

Positioning

  • tellp β€” returns the output position indicator (public member function of std::basic_ostream<CharT,Traits>).
  • seekp β€” sets the output position indicator (public member function of std::basic_ostream<CharT,Traits>).

Miscellaneous

  • flush β€” synchronizes with the underlying storage device (public member function of std::basic_ostream<CharT,Traits>).

Member classes

  • sentry β€” implements basic logic for preparation of the stream for output operations (public member class of std::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 write
  • binary β€” open in binary mode
  • in β€” open for reading
  • out β€” open for writing
  • trunc β€” discard the contents of the stream when opening
  • ate β€” seek to the end of stream immediately after open
  • noreplace (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: see std::dec
  • oct β€” use octal base for integer I/O: see std::oct
  • hex β€” use hexadecimal base for integer I/O: see std::hex
  • basefield β€” dec | oct | hex. Useful for masking operations
  • left β€” left adjustment (adds fill characters to the right): see std::left
  • right β€” right adjustment (adds fill characters to the left): see std::right
  • internal β€” internal adjustment (adds fill characters to the internal designated point): see std::internal
  • adjustfield β€” left | right | internal. Useful for masking operations
  • scientific β€” generate floating point types using scientific notation, or hex notation if combined with fixed: see std::scientific
  • fixed β€” generate floating point types using fixed notation, or hex notation if combined with scientific: see std::fixed
  • floatfield β€” scientific | fixed. Useful for masking operations
  • boolalpha β€” insert and extract bool type in alphanumeric format: see std::boolalpha
  • showbase β€” generate a prefix indicating the numeric base for integer output, require the currency indicator in monetary I/O: see std::showbase
  • showpoint β€” generate a decimal-point character unconditionally for floating-point number output: see std::showpoint
  • showpos β€” generate a + character for non-negative numeric output: see std::showpos
  • skipws β€” skip leading whitespace before certain input operations: see std::skipws
  • unitbuf β€” flush the output after each output operation: see std::unitbuf
  • uppercase β€” replace certain lowercase letters with their uppercase equivalents in certain output operations: see std::uppercase

🌸 iostate β€” state of the stream type (typedef)

The following constants are also defined:

  • goodbit β€” no error
  • badbit β€” irrecoverable stream error
  • failbit β€” 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 stream
  • end β€” the ending of a stream
  • cur β€” 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