delete file cpp
To delete a file in C++, you can use the remove() function from the
- Include the necessary header file:
#include <cstdio>
- Declare a variable to hold the name of the file you want to delete:
const char* filename = "example.txt";
- Use the remove() function to delete the file:
int result = remove(filename);
- Check the result of the remove() function to determine if the file was successfully deleted:
if (result == 0) {
// File deleted successfully
} else {
// Unable to delete the file
}
That's it! By following these steps, you can delete a file using C++.