Namespaces
Variants

std::experimental::filesystem::path::string,wstring,u8string,...

cppreference.net에서
 
 
실험적
기술 사양
파일시스템 라이브러리 (filesystem TS)
라이브러리 기초 (library fundamentals TS)
라이브러리 기초 2 (library fundamentals TS v2)
라이브러리 기초 3 (library fundamentals TS v3)
병렬 처리를 위한 확장 (parallelism TS)
병렬 처리를 위한 확장 2 (parallelism TS v2)
동시성을 위한 확장 (concurrency TS)
동시성을 위한 확장 2 (concurrency TS v2)
개념 (concepts TS)
범위 (ranges TS)
리플렉션 (reflection TS)
수학 특수 함수 (special functions TR)
실험적 비TS
패턴 매칭
선형 대수
std::execution
계약
2D 그래픽
 
 
 
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)