![]() |
VOOZH | about |
The <spanstream> header is a new addition to C++ 23 Standard Libraries Collection. It provides fixed character buffer streams for input and output.
It is a collection of classes and function templates that let you manipulate letter stretch as if they were streams, much like <stringstream> or <istringstream>. However, it works with std::span<char> rather than pulling from or writing to a string or buffer.
The following image illustrates the inheritance diagram of the <spanstream> header file:
#include <spanstream>
The above statement imports all the function and class templates of the <spanstream> header in the std namespace of our program.
Following is the list of classes defined inside the <spanstream> header file:
All these classes have their own member functions and work.
The std:;spanstream is a typedef name defined for basic_spanstream<char> that is nothing but a span-based string I/O buffer. We can initialize the objects of this class using std::span objects and then we can use it like a separate string buffer for input and output.
The following C Program demonstrates the use of spanstream class:
Output
geeks_double1 = 3.45 geeks_double2 = 5.67 geeks_double3 = 4.64 Result: GeeksforGeeks
In the above example, we have used spanstream case to perform both input and output using >> and << operators.
Note: The above code can only be run on the compilers with C++ 23 standard support such as GCC 12 and MSVC 19.31 and onwards.