I know it is possible to truncate a file with
std::fstream fs(mypath, std::fstream::out | std::fstream::trunc);
but I need to read the file, truncate it, then write new contents all with the same file handle (so the whole operation is atomic). Anyone?
See Question&Answers more detail:os