Namespaces
Variants

std::experimental::filesystem:: read_symlink

From cppreference.net
헤더 파일에 정의됨 <experimental/filesystem>
path read_symlink ( const path & p ) ;
path read_symlink ( const path & p, error_code & ec ) ;
(filesystem 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"

참고 항목

인수가 심볼릭 링크를 참조하는지 확인합니다
(함수)
심볼릭 링크를 생성합니다
(함수)
심볼릭 링크를 복사합니다
(함수)
파일 속성을 결정합니다
심볼릭 링크 대상을 확인하여 파일 속성을 결정합니다
(함수)