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

std::filesystem::read_symlink

Defined in header <filesystem>

?

?

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

?

(since C++17)

如果路径p引用一个符号链接,返回一个新的Path对象,该对象引用该符号链接的目标。

这是一个错误,如果p不引用符号链接。

不抛出的重载返回错误的空路径。

参数

p

-

path to a symlink

ec

-

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

返回值

符号链接%28的目标,可能不一定存在%29。

例外

不占用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 typical Linux system, /lib/libc.so.6 is a symlink
    fs::path p = "/lib/libc.so.6";
    if(exists(p) && is_symlink(p))
        std::cout << p << " -> " << read_symlink(p) << '\n';
    else
        std::cout << p << " does not exist or is not a symlink\n";
}

二次

可能的产出:

二次

代码语言:javascript
复制
"/lib/libc.so.6" -> "libc-2.12.so"

二次

另见

is_symlink (C++17)

checks whether the argument refers to a symbolic link (function)

create_symlinkcreate_directory_symlink (C++17)(C++17)

creates a symbolic link (function)

copy_symlink (C++17)

copies a symbolic link (function)

statussymlink_status (C++17)(C++17)

determines file attributesdetermines file attributes, checking the symlink target (function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com