std::ofstream, check if file exists before writing
问题 I am implementing file saving functionality within a Qt application using C++. I am looking for a way to check to see if the selected file already exists before writing to it, so that I can prompt a warning to the user. I am using an std::ofstream and I am not looking for a Boost solution. 回答1: This is one of my favorite tuck-away functions I keep on hand for multiple uses. #include <sys/stat.h> // Function: fileExists /** Check if a file exists @param[in] filename - the name of the file to