std::filesystem::path:: string, std::filesystem::path:: wstring, std::filesystem::path:: u8string, std::filesystem::path:: u16string, std::filesystem::path:: u32string
|
template
<
class
CharT,
class
Traits
=
std::
char_traits
<
CharT
>
,
class
Alloc
=
std::
allocator
<
CharT
>
>
|
(1) | (C++17부터) |
| (2) | (C++17부터) | |
|
std::
string
string
(
)
const
;
|
||
|
std::
wstring
wstring
(
)
const
;
|
||
|
std::
u16string
u16string
(
)
const
;
|
||
|
std::
u32string
u32string
(
)
const
;
|
||
| (3) | ||
|
std::
string
u8string
(
)
const
;
|
(C++17부터)
(C++20까지) |
|
|
std::
u8string
u8string
(
)
const
;
|
(C++20부터) | |
네이티브 경로명 형식으로 변환된 내부 경로명을 특정 문자열 타입으로 반환합니다. 변환이 필요한 경우 다음과 같이 수행됩니다:
-
path::value_type이 char 인 경우, 변환이 있다면 시스템에 종속됩니다. 이는 일반적인 POSIX 시스템(Linux 등)에서 해당하며, 기본 인코딩이 UTF-8이고string()이 변환을 수행하지 않는 경우입니다. -
그렇지 않고
path::value_type이 wchar_t 인 경우, 변환이 있다면 명시되지 않습니다. 이는 Windows에서 해당하며, wchar_t 가 16비트이고 기본 인코딩이 UTF-16인 경우입니다. -
그렇지 않고
path::value_type이 char16_t 인 경우, 기본 인코딩은 UTF-16이고 변환 방법은 명시되지 않습니다. -
그렇지 않고
path::value_type이 char32_t 인 경우, 기본 인코딩은 UTF-32이고 변환 방법은 명시되지 않습니다. -
그렇지 않고
path::value_type이 char8_t 인 경우, 기본 인코딩은 UTF-8이고 변환 방법은 명시되지 않습니다.
목차 |
매개변수
(없음)
반환값
네이티브 경로명 형식의 내부 경로명을 지정된 문자열 타입으로 변환합니다.
예외
구현 정의 예외를 던질 수 있습니다.
예제
#include <clocale> #include <cstdio> #include <filesystem> #include <fstream> #include <iostream> #include <locale> int main() { const char* const localeName = "ja_JP.utf-8"; std::setlocale(LC_ALL, localeName); std::locale::global(std::locale(localeName)); const std::filesystem::path p(u8"要らない.txt"); std::ofstream(p) << "File contents"; // 네이티브 문자열 표현은 OS API와 함께 사용 가능 if (std::FILE* const f = std::fopen(p.string().c_str(), "r")) { for (int ch; (ch = std::fgetc(f)) != EOF;) std::putchar(ch); std::fclose(f); } // 멀티바이트 및 와이드 표현은 출력에 사용 가능 std::cout << "\nFile name in narrow multibyte encoding: " << p.string() << '\n'; // wstring()은 stdlibc++에서 예외를 발생시킴 (gcc-12.1.0 기준), 참조: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95048 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102839 // 최신 gcc-12.2.1 (2023/02/01) 및 clang-10+에서 작동 std::wcout << "File name in wide encoding: " << p.wstring() << '\n'; std::filesystem::remove(p); }
가능한 출력:
File contents File name in narrow multibyte encoding: 要らない.txt File name in wide encoding: 要らない.txt
참고 항목
|
일반 경로명 형식으로 변환된 경로를 문자열로 반환합니다
(public member function) |