ifstream keeps being read even when the file does not exist anymore

If you’re doing this on e.g. linux, then the OS will not actually delete the file until you’ve closed all file handles to it. So it might seem like the file is deleted, but it’s still stored somewhere on disk. See e.g. What happens internally when deleting an opened file in linux.

So if you’re trying to detect this file deletion to prevent wrong reads, then don’t worry, the file won’t actually be deleted.

If you close the stream, and then try and open it again for that file, you’ll get an error. But that also means you won’t be able to read from it…

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top