std::basic_ospanstream<CharT,Traits>:: span
From cppreference.net
<
cpp
|
io
|
basic ospanstream
|
std::
span
<
CharT
>
span
(
)
const
noexcept
;
|
(1) | (desde C++23) |
|
void
span
(
std::
span
<
CharT
>
s
)
noexcept
;
|
(2) | (desde C++23) |
1)
Obtiene un
span
que referencia el área de escritura si
std::ios_base::out
está establecido en el modo de apertura del
std::basic_spanbuf
envuelto, o un
span
que referencia el búfer subyacente en caso contrario.
2)
Hace que el
std::basic_spanbuf
envuelto realice E/S en el búfer referenciado por
s
.
Contenidos |
Parámetros
| s | - | std::span que referencia al almacenamiento que se utilizará como el nuevo búfer subyacente del flujo |
Valor de retorno
1)
Un
std::span
que referencia al búfer subyacente o al área escrita, dependiendo del modo de apertura del
std::basic_spanbuf
envuelto.
2)
(ninguno)
Ejemplo
Ejecutar este código
#include <cassert> #include <iostream> #include <span> #include <spanstream> int main() { char out_buf[16]; std::ospanstream ost{std::span<char>{out_buf}}; ost << "C++" << ' ' << 23 << '\0'; // nota: terminación nula explícita auto sp = ost.span(); assert( sp[0] == 'C' && sp[1] == '+' && sp[2] == '+' && sp[3] == ' ' && sp[4] == '2' && sp[5] == '3' && sp[6] == '\0' ); std::cout << "sp.data(): [" << sp.data() << "]\n"; std::cout << "out_buf: [" << out_buf << "]\n"; // spanstream utiliza out_buf como almacenamiento interno, sin asignaciones assert(static_cast<char*>(out_buf) == sp.data()); const char in_buf[] = "X Y 42"; std::ispanstream ist{std::span<const char>{in_buf}}; assert(static_cast<const char*>(in_buf) == ist.span().data()); char c; ist >> c; assert(c == 'X'); ist >> c; assert(c == 'Y'); int i; ist >> i; assert(i == 42); ist >> i; // el búfer está agotado assert(!ist); }
Salida:
sp.data(): [C++ 23] out_buf: [C++ 23]
Véase también
|
obtiene o inicializa un búfer subyacente según el modo
(función miembro pública de
std::basic_spanbuf<CharT,Traits>
)
|