std::experimental::filesystem::path::string,wstring,u8string,...
cppreference.net에서
template< class CharT, class Traits = std::char_traits<CharT>,
class Alloc = std::allocator<CharT> >
std::basic_string<CharT,Traits,Alloc>
string( const Alloc& a = Alloc() ) const;
|
(1) | (filesystem TS) |
std::string string() const;
|
(2) | (filesystem TS) |
std::wstring wstring() const;
|
(filesystem TS) | |
std::string u8string() const;
|
(filesystem TS) | |
std::u16string u16string() const;
|
(filesystem TS) | |
std::u32string u32string() const;
|
(filesystem TS) | |
네이티브 경로명 형식의 내부 경로명을 반환하며, 특정 문자열 타입으로 변환합니다. 변환이 있는 경우 todo에 명시되어 있습니다.
1) 모든 메모리 할당은
a에 의해 수행됩니다.2)
u8string()의 경우 인코딩은 항상 UTF-8입니다.반환값
네이티브 경로명 형식의 내부 경로명을 지정된 문자열 타입으로 변환합니다.
예외
구현 정의 예외를 던질 수 있습니다.
예제
이 코드 실행
#include <clocale> #include <cstdio> #include <experimental/filesystem> #include <fstream> #include <iostream> namespace fs = std::experimental::filesystem; int main() { std::setlocale(LC_ALL, "en_US.utf8"); std::locale::global(std::locale("en_US.utf8")); fs::path p = fs::u8path(u8"要らない.txt"); // 네이티브 문자열 표현은 OS API와 함께 사용 가능 std::ofstream(p) << "File contents"; // 이는 operator string()을 사용함 if (std::FILE* f = std::fopen(p.c_str(), "r")) { int ch; while ((ch=fgetc(f))!= EOF) putchar(ch); std::fclose(f); } // 멀티바이트 및 와이드 표현은 출력에 사용 가능 std::cout.imbue(std::locale()); std::cout << "\nFile name in narrow multibyte encoding: " << p.string() << '\n'; std::wcerr.imbue(std::locale()); std::wcerr << "File name in wide encoding: " << p.wstring() << '\n'; fs::remove(p); }
가능한 출력:
File contents File name in narrow multibyte encoding: 要らない.txt File name in wide encoding: 要らない.txt
참고 항목
|
경로를 일반 경로명 형식으로 변환한 문자열을 반환합니다
(public member function) |