std::basic_filebuf<CharT,Traits>:: operator=
From cppreference.net
<
cpp
|
io
|
basic filebuf
|
std::
basic_filebuf
&
operator
=
(
std::
basic_filebuf
&&
rhs
)
;
|
(1) | (desde C++11) |
|
std::
basic_filebuf
&
operator
=
(
const
std::
basic_filebuf
&
rhs
)
=
delete
;
|
(2) | |
Asigna otro objeto
basic_filebuf
.
1)
Primero llama a
close()
para cerrar el archivo asociado, luego mueve el contenido de
rhs
a
*
this
: los búferes de escritura y lectura, el archivo asociado, la configuración regional, el modo de apertura, el indicador is_open y cualquier otro estado. Después del movimiento,
rhs
no está asociado con ningún archivo y
rhs.
is_open
(
)
==
false
.
Contenidos |
Parámetros
| rhs | - |
otro
basic_filebuf
del cual se moverá
|
Valor de retorno
* this
Ejemplo
Ejecutar este código
#include <cassert> #include <fstream> #include <iostream> #include <string> int main() { std::ofstream{"test.in"} << "test\n"; // escribe mediante un objeto temporal std::ifstream fin("test.in"); // flujo de solo lectura std::ofstream fout("test.out"); // flujo de solo escritura std::string s; std::getline(fin, s); std::cout << "s = [" << s << "]\n"; // s contiene "test" assert(fout.is_open()); *fin.rdbuf() = std::move(*fout.rdbuf()); assert(!fout.is_open()); std::getline(fin, s); std::cout << "s = [" << s << "]\n"; // s es entrada vacía }
Salida:
s = [test] s = []
Véase también
construye un objeto
basic_filebuf
(función miembro pública) |
|
|
(C++11)
|
intercambia dos objetos
basic_filebuf
(función miembro pública) |