dimanche 20 décembre 2020

ofstreamFile << ifstreamFile.rdbuf() fails but file text from file is written to ofstreamFile correctly

std::ifstream inFile;
std::ofstream outFile;
// ...
outFile << inFile.rdbuf();

I was writing one file into another with rdbuf, everything was good. I decided to add error check

std::ifstream inFile;
std::ofstream outFile;
// ...
if(!(outFile << inFile.rdbuf()))
// error message

And on the same files it started to fail all the time, but the text is copied into the outFile . But if I check

std::ifstream inFile;
std::ofstream outFile;
// ...
outFile << inFile.rdbuf();
if (inFil2.bad() || !inFile2.good())
  // error message

There is no error message and program runs good, I got my file copied.

Aucun commentaire:

Enregistrer un commentaire