std::experimental::filesystem:: canonical
|
헤더 파일에 정의됨
<experimental/filesystem>
|
||
|
path canonical
(
const
path
&
p,
const
path
&
base
=
current_path
(
)
)
;
|
(1) | (filesystem TS) |
|
path canonical
(
const
path
&
p, error_code
&
ec
)
;
|
(2) | (filesystem TS) |
|
path canonical
(
const
path
&
p,
const
path
&
base, error_code
&
ec
)
;
|
(3) | (filesystem TS) |
경로 p 를 정규 절대 경로로 변환합니다. 즉, 점, 점-점 요소 또는 심볼릭 링크가 없는 절대 경로입니다.
만약 p 가 절대 경로가 아닌 경우, 이 함수는 마치 먼저 absolute ( p, base ) 또는 absolute ( p ) 에 의해 절대 경로로 만들어진 것처럼 동작합니다 (2) .
경로 p 가 존재해야 합니다.
목차 |
매개변수
| p | - | 절대 경로이거나 base 에 상대적인 경로이며, 반드시 존재하는 경로여야 함 |
| base | - | p 가 상대 경로인 경우 사용할 기준 경로 |
| ec | - | 오류 상태를 저장할 에러 코드 |
반환값
absolute ( p, base ) (또는 (2) 의 경우 absolute ( p ) )와 동일한 파일로 확인되는 절대 경로입니다.
예외
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, base as the second 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이 함수는 POSIX realpath 를 모델로 하여 설계되었습니다.
예제
#include <experimental/filesystem> #include <iostream> namespace fs = std::experimental::filesystem; int main() { fs::path p = fs::path("..") / ".." / "AppData"; std::cout << "Current path is " << fs::current_path() << '\n' << "Canonical path for " << p << " is " << fs::canonical(p) << '\n'; }
가능한 출력:
Current path is "C:\Users\abcdef\AppData\Local\Temp" Canonical path for "..\..\AppData" is "C:\Users\abcdef\AppData"
참고 항목
|
경로를 나타냄
(클래스) |
|
|
절대 경로를 구성함
OS별 동작을 복제하여 경로를 절대 경로로 변환함 (함수) |