std::istrst...::istrstream(3)
πΈ NAME πΈ
Bestie, welcome to std::istrst...::istrstream(3) from the C++ Standard Libary. The main character today is std::istrstream::istrstream β literally std::istrstream::istrstream, name matching name, constructor energy for days. π
β¨ Synopsis β¨
explicit istrstream( const char* s ); (1) (deprecated in C++98)
(removed in C++26)
explicit istrstream( char* s ); (2) (deprecated in C++98)
(removed in C++26)
istrstream( const char* s, std::streamsize n ); (3) (deprecated in C++98)
(removed in C++26)
istrstream( char* s, std::streamsize n ); (4) (deprecated in C++98)
(removed in C++26)
π Description π
Okay so these constructors build a fresh std::istrstream and its underlying std::strstreambuf. The underlying std::strstreambuf is lowkey doing the real work here. π«Ά
- For
(1)and(2): constructs the underlyingstd::strstreambufby callingstrstreambuf(s, 0), then initializes the base class with the address of thestrstreambuf. Behavior is undefined ifsis not pointing at an element of a null-terminated array. Not me warning you dramatically, but also yes. π - For
(3)and(4): constructs the underlyingstd::strstreambufby callingstrstreambuf(s, n), then initializes the base class with the address of thestrstreambuf. Behavior is undefined ifsis not pointing at an element of an array whose length is at leastnelements.
πΈ Parameters πΈ
sβ C-string orchararray to use as the contents of the stream.nβ size of the array.
π Example π
// Run this code
#include <iostream>
#include <strstream>
int main()
{
std::istrstream s1("1 2 3"); // string literal
int n1, n2, n3;
if (s1 >> n1 >> n2 >> n3)
std::cout << n1 << ", " << n2 << ", " << n3 << '\n';
char arr[] = {'4', ' ', '5', ' ', '6'};
std::istrstream s2(arr, sizeof arr);
if (s2 >> n1 >> n2 >> n3)
std::cout << n1 << ", " << n2 << ", " << n3 << '\n';
}
π Output: π
1, 2, 3
4, 5, 6
π¦ See also π¦
- constructor β constructs a
strstreambufobject (public member function ofstd::strstreambuf) - constructor β constructs an
ostrstreamobject, optionally allocating the buffer (public member function ofstd::ostrstream) - constructor β constructs a
strstreamobject, optionally allocating the buffer (public member function ofstd::strstream)
Thatβs the whole vibe check, bestie: this iconic page came from http://cppreference.com, dated 2024.06.10, for std::istrst...::istrstream(3). Sheβs deprecated in C++98 and removed in C++26 β legendary, but not forever. πβ¨
π¦ 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