名稱空間
變體
操作

std::experimental::filesystem::path::parent_path

來自 cppreference.com
< cpp‎ | experimental‎ | fs‎ | path
 
 
實驗性
技術規範
檔案系統庫 (檔案系統 TS)
庫基礎 (庫基礎 TS)
庫基礎 2 (庫基礎 TS v2)
庫基礎 3 (庫基礎 TS v3)
並行性擴充套件 (並行性 TS)
並行性擴充套件 2 (並行性 TS v2)
併發性擴充套件 (併發性 TS)
併發擴充套件 2 (併發 TS v2)
概念 (概念 TS)
範圍 (範圍 TS)
反射 (反射 TS)
數學特殊函式 (特殊函式 TR)
實驗性非 TS
模式匹配
線性代數
std::execution
契約
2D 圖形
 
 
 
path parent_path() const;
(檔案系統 TS)

返回父目錄的路徑。如果 empty() 為真,或者路徑中只有一個元素 (begin() == --end()),則返回空路徑。

結果路徑是透過將範圍 [begin()--end()) 中的所有元素附加到一個空路徑來構造的。

目錄

[編輯] 引數

(無)

[編輯] 返回值

父目錄的路徑。

[編輯] 異常

可能丟擲實現定義的異常。

[編輯] 示例

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
 
int main()
{
    for (fs::path p : {"/var/tmp/example.txt", "/", "/var/tmp/."})
        std::cout << "The parent path of " << p
                  << " is " << p.parent_path() << '\n';
}

可能的輸出

The parent path of "/var/tmp/example.txt" is "/var/tmp"
The parent path of "/" is ""
The parent path of "/var/tmp/." is "/var/tmp"

[編輯] 參閱