(C++) DeleteFile
February 24, 2017 · View on GitHub
(C++) DeleteFile
DeleteFile is a file I/O code snippet to delete a file.
#include <cassert> #include <cstdio> #include <fstream> int main() { const std::string filename = "tmp.txt"; { //Check that file is not present std::ifstream file(filename.c_str()); assert(!file.is_open()); } { //Create file std::ofstream file(filename.c_str()); } { //Check that file is present std::ifstream file(filename.c_str()); assert(file.is_open()); } { //Delete file std::remove(filename.c_str()); } { //Check that file is not present std::ifstream file(filename.c_str()); assert(!file.is_open()); } }