std::filesystem::path::relative_path
來自 cppreference.com
< cpp | filesystem | path
path relative_path() const; |
(C++17 起) | |
返回相對於 根路徑 (root-path) 的路徑,即由 *this 的通用格式元件中位於 根路徑 (root-path) 之後的部分組成的路徑名。如果 *this 是空路徑,則返回空路徑。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
相對於根路徑的路徑。
[編輯] 異常
可能丟擲實現定義的異常。
[編輯] 示例
執行此程式碼
#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'; }
可能的輸出
The current path "C:\Users\abcdef\Local Settings\temp" decomposes into: root-path "C:\" relative path "Users\abcdef\Local Settings\temp"
[編輯] 參閱
返回路徑的根名(如果存在) (public member function) | |
返回路徑的根目錄(如果存在) (public member function) | |
返回路徑的根路徑(如果存在) (public member function) |