std::experimental::filesystem:: read_symlink
From cppreference.net
<
cpp
|
experimental
|
fs
|
定义于头文件
<experimental/filesystem>
|
||
|
path read_symlink
(
const
path
&
p
)
;
path read_symlink ( const path & p, error_code & ec ) ; |
(文件系统 TS) | |
如果路径 p 指向符号链接,则返回引用该符号链接目标的新路径对象。
如果 p 未指向符号链接,则属于错误。
非抛出重载在出错时返回空路径。
目录 |
参数
| p | - | 符号链接路径 |
| ec | - | 非抛出重载中用于错误报告的输出参数 |
返回值
符号链接的目标(该目标不一定实际存在)。
异常
The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with p as the first argument and the OS error code as the error code argument. std:: bad_alloc may be thrown if memory allocation fails. The overload taking an error_code & parameter sets it to the OS API error code if an OS API call fails, and executes ec. clear ( ) if no errors occur. This overload has
noexcept
规范:
noexcept
示例
运行此代码
#include <experimental/filesystem> #include <iostream> namespace fs = std::experimental::filesystem; int main() { // 在典型的 Linux 系统上,/lib/libc.so.6 是一个符号链接 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"; }
可能的输出:
"/lib/libc.so.6" -> "libc-2.12.so"
参见
|
检查参数是否指向符号链接
(函数) |
|
|
创建符号链接
(函数) |
|
|
复制符号链接
(函数) |
|
|
确定文件属性
确定文件属性,检查符号链接目标 (函数) |