i want to save some runtime log into a file on embedded device, running on linux system. this file is opened by std::ofstream. for debug purpose i will copy this log file to my local PC, but this file may be delete by me by mistake, so is there any flag to check this file is still exist or stream is good. or there is some way to auto create a new file when it be deleted
The (deleted) part tells you that the file has gone from the file system.
Assuming you want to keep data written after the file was deleted (either intentionally or accidentally), you need to open/write/close.
You don't need to open/close every time, but you should certainly do so periodically.
you can also set its (or a folder above its) permissions so it cannot be deleted accidentally.
Its none of my business but using linux and 'accidentally deleting files' is going to be a problem for you. Like a carpenter, measure twice, cut once, when it comes to deleting files. Which translates to 'do a ls with the delete wildcard you plan to use before deleting'.