Datei mit C++17-filesystem-Bibliothek löschen
English
Deutsch
To remove a file (for example test.txt) use remove from the C++17 filesystem library:
remove-example.cpp
remove("test.txt");Vollständiges Beispiel:
delete-cpp17.cpp
#include <experimental/filesystem>
using namespace std::experimental::filesystem;
int main() {
remove("test.txt");
}Falls du GCC verwendest, musst du die Datei so kompilieren:
build-delete-cpp17.sh
g++ -o delete-cpp17 delete-cpp17.cpp -lstdc++fsDu musst die stdc++fs-Bibliothek linken, damit die Funktionen aus der C++17-filesystem-Bibliothek deinem Programm zur Verfügung stehen.
Note that remove does not recursively remove directories! Use remove_all or see How to recursively delete directory using C++17 filesystem library
Check out similar posts by category:
C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow