名稱空間
變體
操作

std::experimental::filesystem::hard_link_count

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

返回由路徑 p 標識的檔案系統物件的硬連結數量。

不丟擲異常的過載在出錯時返回 static_cast<uintmax_t>(-1)

目錄

[編輯] 引數

p - 要檢查的路徑
ec - 非丟擲過載中用於錯誤報告的出參

[編輯] 返回值

p 的硬連結數量。

[編輯] 異常

不帶 error_code& 引數的過載在底層作業系統 API 錯誤時丟擲 filesystem_error,該異常以 p 作為第一個引數,作業系統錯誤碼作為錯誤碼引數構造。如果記憶體分配失敗,可能會丟擲 std::bad_alloc。帶有 error_code& 引數的過載,如果作業系統 API 呼叫失敗,則將其設定為作業系統 API 錯誤碼;如果沒有發生錯誤,則執行 ec.clear()。此過載具有
noexcept 規範:  
noexcept
  

[編輯] 示例

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
 
int main()
{
    // On a POSIX-style filesystem, each directory has at least 2 hard links:
    // itself and the special member pathname "."
    fs::path p = fs::current_path();
    std::cout << "Number of hard links for current path is "
              << fs::hard_link_count(p) << '\n';
 
    // each ".." is a hard link to the parent directory, so the total number
    // of hard links for any directory is 2 plus number of direct subdirectories
    p = fs::current_path() / ".."; // each dot-dot is a hard link to parent
    std::cout << "Number of hard links for .. is "
              << fs::hard_link_count(p) << '\n';
}

輸出

Number of hard links for current path is 2
Number of hard links for .. is 3

[編輯] 參見

建立硬連結
(函式) [編輯]