std::filesystem::equivalent
| Defined in header <filesystem> |  |  | 
|---|---|---|
| bool equivalent( const std::filesystem::path& p1, const std::filesystem::path& p2 ); bool equivalent( const std::filesystem::path& p1, const std::filesystem::path& p2, std::error_code& ec ); | (1) | (since C++17) | 
检查路径p1和p2引用相同的文件或目录,并具有与status%28符号链接跟随%29。
如果两者都没有p1也不p2存在,或者如果两者都存在,但文件、目录或符号链接%28不存在。is_other%29,报告了一个错误。
非抛出重载返回。false关于错误。
参数
| p1, p2 | - | paths to check for equivalence | 
|---|---|---|
| ec | - | out-parameter for error reporting in the non-throwing overload | 
返回值
true如果p1和p2引用同一个文件或目录,它们的文件状态是相同的。false否则。
例外
不占用std::error_code&参数抛文件系统[医]误差关于基础OS API错误,使用p1作为第一个论点,p2作为第二个参数,操作系统错误代码作为错误代码参数。std::bad_alloc如果内存分配失败,则可能引发。过载std::error_code&参数,如果OSAPI调用失败,则将其设置为OSAPI错误代码,并执行ec.clear()如果没有错误发生。这个过载
noexcept规格:
noexcept
注记
特别是,同一文件或目录的所有硬链接都是等效的,而符号链接及其在同一文件系统上的目标是等效的。
例
二次
#include <iostream>
#include <cstdint>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
    // hard link equivalency
    fs::path p1 = ".";
    fs::path p2 = fs::current_path();
    if(fs::equivalent(p1, p2))
        std::cout << p1 << " is equivalent to " << p2 << '\n';
 
    // symlink equivalency
    fs::path p3 = "/lib/libc.so.6";
    fs::path p4 = p3.parent_path() / fs::read_symlink(p3);
    if(fs::equivalent(p3, p4))
        std::cout << p3 << " is equivalent to " << p4 << '\n';
}二次
可能的产出:
二次
"." is equivalent to "/var/tmp/test"
"/lib/libc.so.6" is equivalent to "/lib/libc-2.12.so"二次
另见
| statussymlink_status (C++17)(C++17) | determines file attributesdetermines file attributes, checking the symlink target (function) | 
|---|
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

