std::experimental::filesystem::path:: c_str, std::experimental::filesystem::path:: native, std::experimental::filesystem::path:: operator string_type()
From cppreference.net
<
cpp
|
experimental
|
fs
|
path
|
const
value_type
*
c_str
(
)
const
;
|
(1) | (filesystem TS) |
|
const
string_type
&
native
(
)
const
;
|
(2) | (filesystem TS) |
|
operator string_type
(
)
const
;
|
(3) | (filesystem TS) |
네이티브 경로 이름을 문자열로 접근합니다.
1)
다음에 해당함
native
(
)
.
c_str
(
)
.
2)
경로 이름의 기본 문자열 표현을 참조로 반환합니다.
3)
경로명의 기본 문자열 표현을 값으로 반환합니다.
목차 |
매개변수
(없음)
반환값
경로 이름의 기본 문자열 표현으로, 기본 구문, 기본 문자 유형 및 기본 문자 인코딩을 사용합니다. 이 문자열은 OS API와 함께 사용하기에 적합합니다.
예외
1,2)
noexcept
명세:
noexcept
참고 사항
변환 함수 (3) 는 std::basic_string 파일 이름을 받는 표준 파일 열기 API들(예: std::ifstream 생성자)이 코드 변경 없이 경로명을 사용할 수 있도록 제공됩니다:
fs::path p = "/tmp/text.txt"; std::ifstream f(p);
예제
이 코드 실행
#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) |
|
|
일반 경로명 형식으로 변환된 경로를 문자열로 반환합니다
(public member function) |