std::basic_ispanstream<CharT,Traits>::basic_ispanstream
From cppreference.com
< cpp | io | basic ispanstream
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Input/output library
Print functions (C++23)
Buffers
(C++23)
(C++98/26*)
(C++20)
Streams
Abstractions
File I/O
String I/O
Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
Synchronized Output
(C++20)
Types
Error category interface
(C++11)
(C++11)
explicit basic_ispanstream( std::span <CharT> s, std::ios_base::openmode mode =
std::ios_base::in );
(1)
(since C++23)
std::ios_base::in );
template< class ROS >
explicit basic_ispanstream( ROS&& r );
(2)
(since C++23)
explicit basic_ispanstream( ROS&& r );
basic_ispanstream( basic_ispanstream&& rhs );
(3)
(since C++23)
basic_ispanstream( const basic_ispanstream& ) = delete;
(4)
(since C++23)
Constructs a new basic_ispanstream
.
1) Uses the storage referenced by s as initial underlying buffer of the wrapped std::basic_spanbuf device. The wrapped std::basic_spanbuf object is constructed as basic_spanbuf<Char, Traits>(s, mode | std::ios_base::in ).
2) Uses the storage referenced by r after converted to std::span <const CharT> as initial underlying buffer of the wrapped std::basic_spanbuf device. The wrapped std::basic_spanbuf object is opened in mode std::ios_base::in . This overload participates in overload resolution only if
ROS
models borrowed_range
, std::convertible_to <ROS, std::span <CharT>> is false, and std::convertible_to <ROS, std::span <const CharT>> is true.3) Move constructor. Move constructs the std::basic_istream base subobject and the wrapped std::basic_spanbuf from those of rhs, and then calls set_rdbuf with the address of the wrapped std::basic_spanbuf in *this to install it.
4) Copy constructor is deleted.
basic_ispanstream
is not copyable.Contents
[edit] Parameters
s
-
std::span referencing the storage to be use as initial underlying buffer of stream
r
-
borrowed_range
to be use as initial underlying buffer of stream
mode
-
specifies stream open mode. Following constants and bit-wise OR between them may be used:
Constant
Explanation
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
other
-
another
basic_ispanstream
to be moved from
[edit] Exceptions
May throw implementation-defined exceptions.
[edit] Example
Run this code
#include <print> #include <spanstream> #include <string> int main() { std::ispanstream is("1 2 3 abc"); int i, j, k; std::string w; is >> i >> j >> k >> w; std::print ("i={}, j={}, k={}, w={}", i, j, k, w); }
Output:
i=1, j=2, k=3, w=abc
[edit] See also
constructs a
(public member function of
basic_spanbuf
object (public member function of
std::basic_spanbuf<CharT,Traits>
) [edit]