首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::filesystem::hard_link_count

Defined in header <filesystem>

?

?

std::uintmax_t hard_link_count( const std::filesystem::path& p ); std::uintmax_t hard_link_count( const std::filesystem::path& p, std::error_code& ec );

(1)

(since C++17)

返回按路径标识的文件系统对象的硬链接数。p...

非抛出重载返回。static_cast<uintmax_t>(-1)关于错误。

参数

p

-

path to examine

ec

-

out-parameter for error reporting in the non-throwing overload

返回值

的硬链接数p...

例外

不占用std::error_code&参数抛文件系统[医]误差关于基础OS API错误,使用p作为第一个参数和操作系统错误代码作为错误代码参数。std::bad_alloc如果内存分配失败,则可能引发。过载std::error_code&参数,如果OSAPI调用失败,则将其设置为OSAPI错误代码,并执行ec.clear()如果没有错误发生。这个过载

noexcept规格:

noexcept

二次

代码语言:javascript
复制
#include <iostream>
#include <filesystem>
namespace fs = std::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';
}

二次

可能的产出:

二次

代码语言:javascript
复制
Number of hard links for current path is 2
Number of hard links for .. is 3

二次

另见

create_hard_link (C++17)

creates a hard link (function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com