std::filesystem::path::relative_path
Von cppreference.com
< cpp | filesystem | path
| path relative_path() const; |
(seit C++17) | |
Gibt den Pfad relativ zum root-path zurück, d. h. ein Pfadname, der aus jeder generischen Komponente von *this nach root-path zusammengesetzt ist. Wenn *this ein leerer Pfad ist, wird ein leerer Pfad zurückgegeben.
Inhalt |
[edit] Parameter
(keine)
[edit] Rückgabewert
Pfad relativ zum root path.
[edit] Exceptions
Kann implementierungsdefinierte Ausnahmen auslösen.
[edit] Beispiel
Führen Sie diesen Code aus
#include <filesystem> #include <iostream> namespace fs = std::filesystem; int main() { fs::path p = fs::current_path(); std::cout << "The current path " << p << " decomposes into:\n" << "root-path " << p.root_path() << '\n' << "relative path " << p.relative_path() << '\n'; }
Mögliche Ausgabe
The current path "C:\Users\abcdef\Local Settings\temp" decomposes into: root-path "C:\" relative path "Users\abcdef\Local Settings\temp"
[edit] Siehe auch
| gibt den Root-Namen des Pfades zurück, falls vorhanden (public member function) | |
| gibt das Root-Verzeichnis des Pfades zurück, falls vorhanden (public member function) | |
| gibt den Root-Pfad des Pfades zurück, falls vorhanden (public member function) |