0
I am trying to pass a binary file that is already open to a function. However, I get the following error:
error: use of Deleted Function.
Code:
void abreBin(){
fstream arq_bin("registro.bin", ios::in|ios::binary)
....
// remove é uma funcao do tipo bool
if(Remove(arq_bin)) // <--- erro acusa nesta linha
cout << "item removido" << endl;
else
cout << "item nao encontrado" << endl;
}
Note: The error only happens when I try to pass the variable arq_bin
to the other function.
I tried to use libraries type includes bool
, but it didn’t work. I tried to pass other variables to the function and saw that the problem only occurs with variable fstream
.
Precisely, I discovered this solution yesterday, I was going to answer now kkk. I just did not understand the reason of
fstream
do not allow copying operation, you know explain?– Filipi Maciel
The copying operation makes no sense for streams. You can understand a stream as an object that "points" to an input/output of data, and does not store it. When copying a stream you would have two objects "pointing" to the same input/output. Imagine that in one of the objects you closed this input/output: you would continue with an object pointing at it, which adds insecurity in the code, if for example you tried to read this input/output that was closed.
– Kaike Alves Silva