std::filesystem::path:: c_str, std::filesystem::path:: native, std::filesystem::path:: operator string_type()
From cppreference.net
<
cpp
|
filesystem
|
path
C++
std::filesystem::path
| Member types | ||||||||||||||||||||||||||
| Member constants | ||||||||||||||||||||||||||
| Member functions | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| Path decomposition | ||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| Helper classes | ||||||||||||||||||||||||||
|
const
value_type
*
c_str
(
)
const
noexcept
;
|
(1) | (C++17부터) |
|
const
string_type
&
native
(
)
const
noexcept
;
|
(2) | (C++17부터) |
|
operator string_type
(
)
const
;
|
(3) | (C++17부터) |
네이티브 경로 이름을 문자열로 접근합니다.
1)
다음에 해당함
native
(
)
.
c_str
(
)
.
2)
경로명의 네이티브 형식 표현을 참조로 반환합니다.
3)
경로 이름의 네이티브 형식 표현을 값으로 반환합니다.
목차 |
매개변수
(없음)
반환값
경로명의 기본 문자열 표현으로, 기본 구문, 기본 문자 유형 및 기본 문자 인코딩을 사용합니다. 이 문자열은 OS API와 함께 사용하기에 적합합니다.
참고 사항
변환 함수 (3) 는 std::basic_string 파일 이름을 받아들이는 API들이 코드 변경 없이 경로명을 사용할 수 있도록 제공됩니다.
예제
이 코드 실행
#include <cstdio> #ifdef _MSC_VER #include <fcntl.h> #include <io.h> #else #include <clocale> #include <locale> #endif #include <filesystem> #include <fstream> int main() { #ifdef _MSC_VER _setmode(_fileno(stderr), _O_WTEXT); #else std::setlocale(LC_ALL, ""); std::locale::global(std::locale("")); #endif std::filesystem::path p(u8"要らない.txt"); std::ofstream(p) << "File contents"; // LWG2676 이전에는 operator string_type()을 사용함 // MSVC에서는 string_type이 wstring이므로 // 비표준 확장으로만 동작함 // LWG2676 이후에는 새로운 fstream 생성자 사용 // 기본 문자열 표현은 OS별 API와 함께 사용 가능 #ifdef _MSC_VER if (std::FILE* f = _wfopen(p.c_str(), L"r")) #else if (std::FILE* f = std::fopen(p.c_str(), "r")) #endif { for (int ch; (ch = fgetc(f)) != EOF; std::putchar(ch)) {} std::fclose(f); } std::filesystem::remove(p); }
가능한 출력:
File contents
참고 항목
|
네이티브 경로명 형식으로 변환된 문자열로 경로를 반환합니다
(public member function) |
|
|
일반 경로명 형식으로 변환된 문자열로 경로를 반환합니다
(public member function) |