std::filesystem::path::generic_string, std::filesystem::path::generic_wstring, std::filesystem::path::generic_u8string, std::filesystem::path::generic_u16string, std::filesystem::path::generic_u32string
cppreference.net에서
template< class CharT, class Traits = std::char_traits<CharT>,
class Alloc = std::allocator<CharT> >
std::basic_string<CharT,Traits,Alloc>
generic_string( const Alloc& a = Alloc() ) const;
|
(1) | (C++17부터) |
std::string generic_string() const;
|
(2) | (C++17부터) |
std::wstring generic_wstring() const;
|
(3) | (C++17부터) |
std::u16string generic_u16string() const;
|
(4) | (C++17부터) |
std::u32string generic_u32string() const;
|
(5) | (C++17부터) |
std::string generic_u8string() const;
|
(6) | (C++17부터) (C++20까지) |
std::u8string generic_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이며 변환 방법은 지정되지 않습니다.
/ 문자가 디렉터리 구분자로 사용됩니다.
1) 모든 메모리 할당은
a에 의해 수행됩니다.6)
u8string()의 경우 결과 인코딩은 항상 UTF-8입니다.매개변수
| a | - | 문자열을 구성하는 데 사용할 할당자 |
| 타입 요구사항 | ||
-
CharT
는 인코딩된 문자 타입 중 하나여야 함 (
char
,
wchar_t
,
char8_t
(C++20부터)
,
char16_t
및
char32_t
).
|
||
반환값
일반 경로명 형식의 내부 경로명을 지정된 문자열 타입으로 변환한 것입니다.
예외
구현에서 정의된 예외를 던질 수 있습니다.
예제
이 코드 실행
#include <cstddef> #include <filesystem> #include <iomanip> #include <iostream> #include <span> #include <string_view> void print(std::string_view rem, auto const& str) { std::cout << rem << std::hex << std::uppercase << std::setfill('0'); for (const auto b : std::as_bytes(std::span{str})) std::cout << std::setw(2) << std::to_integer<unsigned>(b) << ' '; std::cout << '\n'; } int main() { std::filesystem::path p{"/家/屋"}; std::cout << p << '\n'; print("string : ", p.generic_string()); print("u8string : ", p.generic_u8string()); print("u16string : ", p.generic_u16string()); print("u32string : ", p.generic_u32string()); print("wstring : ", p.generic_wstring()); }
가능한 출력:
"/家/屋" string : 2F E5 AE B6 2F E5 B1 8B u8string : 2F E5 AE B6 2F E5 B1 8B u16string : 2F 00 B6 5B 2F 00 4B 5C u32string : 2F 00 00 00 B6 5B 00 00 2F 00 00 00 4B 5C 00 00 wstring : 2F 00 00 00 B6 5B 00 00 2F 00 00 00 4B 5C 00 00
참고 항목
|
네이티브 경로명 형식으로 변환된 문자열로 경로를 반환합니다
(public member function) |