Why am I doing a "use remote" function when passing a std :: ofstream parameter as a parameter?
I have a dick std::ofstream fBinaryFile
and
void setFile( std::ofstream& pBinaryFile )
{
fBinaryFile = pBinaryFile;
}
output:
Data.h:86:16: error: use of deleted function ‘std::basic_ofstream<char>& std::basic_ofstream<char>::operator=(const
std::basic_ofstream<char>&)’
fBinaryFile = pBinaryFile;
^
I realized that a copy in is std::ofstream
not allowed and perhaps I am missing something. Is it possible to save content pBinaryFile
to fBinaryfile
?
source to share
If you want to copy the contents of pBinaryFile to fBinaryFile, you need to declare pBinaryfile as ifstream (input file stream), not stream (output file stream) It should look something like this:
std::ifstream pBinaryFile;
std::ofstream fBinaryFile;
std::stringstream sstream;
std::string line
pBinaryFile.open(pBinaryFileName.c_str());
fBinaryFile.open(fBinaryFileName.c_str());
if (pBinaryFile.isopen()) {
while (pBinaryFile.good()) {
getline(pBinaryFile, line);
fBinaryFile << sstream(line) << endl;
}
}
pBinaryFile.close();
fBinaryFile.close();
Note that pBinaryFileName and fBinaryFileName refer to your file paths.
There may be errors in this code, but I think the solution is similar to this.
I suggest this for further reading:
source to share