다음을 통해 공유


path 클래스

클래스는 path 경로 이름으로 사용하기에 적합한 박람회 목적으로 여기에 호출 myname 되는 형식string_type의 개체를 저장합니다. string_type는 Windows 또는 char POSIX의 동의어인 동의어 wchar_tbasic_string<value_type>value_type 입니다.

자세한 내용 및 코드 예제를 보려면 파일 시스템 탐색(C++)을 참조하세요.

구문

class path;

생성자

생성자 Description
path path를 생성합니다.

Typedef

형식 이름 설명
const_iterator iterator의 동의어입니다.
iterator 의 구성 요소를 지정 path 하는 양방향 상수 반복기입니다 myname.
string_type 이 형식은 basic_string<value_type>의 동의어입니다.

멤버 함수

멤버 함수 설명
append 필요에 따라 지정된 시퀀스를 mypath변환하고 preferred_separator 삽입합니다.
assign mypath 필요에 따라 변환된 지정된 시퀀스로 바꿉니다.
begin path::iterator 경로 이름에 있는 첫 번째 경로 요소(있는 경우)를 지정하는 값을 반환합니다.
c_str 의 첫 번째 문자에 대한 포인터를 반환합니다 mypath.
clear 를 실행합니다.mypath.clear()
compare 비교 값을 반환합니다.
concat 필요에 따라 지정된 시퀀스를 변환된 시퀀스에 mypath추가합니다(구분 기호를 삽입하지 않음).
empty mypath.empty()을(를) 반환합니다.
end 형식 iterator의 시퀀스 끝 반복기를 반환합니다.
extension 의 접미사를 반환합니다 filename().
filename 특히 .의 myname루트 디렉터리 구성 요소를 반환합니다 empty() ? path() : *--end(). 구성 요소는 비어 있을 수 있습니다.
generic_string 슬래시로 변환된 백슬래시와 함께 this->string<Elem, Traits, Alloc>(al)를 반환합니다(Windows).
generic_u16string 슬래시로 변환된 백슬래시와 함께 u16string()를 반환합니다(Windows).
generic_u32string 슬래시로 변환된 백슬래시와 함께 u32string()를 반환합니다(Windows).
generic_u8string 슬래시로 변환된 백슬래시와 함께 u8string()를 반환합니다(Windows).
generic_wstring 슬래시로 변환된 백슬래시와 함께 wstring()를 반환합니다(Windows).
has_extension !extension().empty()을(를) 반환합니다.
has_filename !filename().empty()을(를) 반환합니다.
has_parent_path !parent_path().empty()을(를) 반환합니다.
has_relative_path !relative_path().empty()을(를) 반환합니다.
has_root_directory !root_directory().empty()을(를) 반환합니다.
has_root_name !root_name().empty()을(를) 반환합니다.
has_root_path !root_path().empty()을(를) 반환합니다.
has_stem !stem().empty()을(를) 반환합니다.
is_absolute Windows의 경우 함수는 .를 반환합니다 has_root_name() && has_root_directory(). POSIX의 경우 함수는 .를 반환합니다 has_root_directory().
is_relative !is_absolute()을(를) 반환합니다.
make_preferred 필요에 따라 각 구분 기호를 변환 preferred_separator 합니다.
native 경로의 네이티브 표현을 반환합니다.
parent_path 의 부모 경로 구성 요소를 반환합니다 myname.
preferred_separator 상수 개체는 호스트 운영 체제에 따라 경로 구성 요소를 구분하는 기본 문자를 제공합니다.
relative_path 의 상대 경로 구성 요소를 반환합니다 myname.
remove_filename 파일 이름을 제거합니다.
replace_extension 의 확장을 myname바꿉니다.
replace_filename 파일 이름을 바꿉니다.
root_directory 의 루트 디렉터리 구성 요소를 myname반환합니다.
root_name 의 루트 이름 구성 요소를 반환합니다 myname.
root_path 의 루트 경로 구성 요소를 반환합니다 myname.
stem stem 구성 요소를 반환합니다 myname.
string 에 저장된 시퀀스를 변환합니다 mypath.
swap 를 실행합니다.swap(mypath, right.mypath)
u16string 저장된 mypath 시퀀스를 UTF-16으로 변환하고 형식 u16string의 개체에 저장된 시퀀스를 반환합니다.
u32string 저장된 mypath 시퀀스를 UTF-32로 변환하고 형식 u32string의 개체에 저장된 시퀀스를 반환합니다.
u8string 저장된 mypath 시퀀스를 UTF-8로 변환하고 형식 u8string의 개체에 저장된 시퀀스를 반환합니다.
value_type 형식은 호스트 운영 체제에서 선호하는 경로 요소를 설명합니다.
wstring 시퀀스에 대해 호스트 시스템에서 wchar_t 선호하는 인코딩으로 저장된 mypath 시퀀스를 변환하고 형식wstring의 개체에 저장된 시퀀스를 반환합니다.

연산자

연산자 설명
operator= 경로의 요소를 다른 경로의 복사본으로 바꿉니다.
operator+= 다양한 concat 식입니다.
operator/= 다양한 append 식입니다.
operator string_type myname을(를) 반환합니다.

요구 사항

헤더<filesystem>:

네임스페이스:std::experimental::filesystem

path::append

지정된 시퀀스를 mypath필요에 따라 변환 및 삽입에 preferred_separator 추가합니다.

template <class Source>
path& append(const Source& source);

template <class InIt>
path& append(InIt first, InIt last);

매개 변수

source
지정된 시퀀스입니다.

first
지정된 시퀀스의 시작입니다.

last
지정된 시퀀스의 끝입니다.

path::assign

mypath 필요에 따라 변환된 지정된 시퀀스로 바꿉니다.

template <class Source>
path& assign(const Source& source);

template <class InIt>
path& assign(InIt first, InIt last);

매개 변수

source
지정된 시퀀스입니다.

first
지정된 시퀀스의 시작입니다.

last
지정된 시퀀스의 끝입니다.

path::begin

path::iterator 경로 이름에 있는 첫 번째 경로 요소(있는 경우)를 지정하는 값을 반환합니다.

iterator begin() const;

path::c_str

의 첫 번째 문자에 대한 포인터를 반환합니다 mypath.

const value_type& *c_str() const noexcept;

path::clear

를 실행합니다.mypath.clear()

void clear() noexcept;

path::compare

첫 번째 함수는 mypath.compare(pval.native())를 반환합니다. 두 번째 함수는 mypath.compare(str)를 반환합니다. 세 번째 함수 mypath.compare(ptr)는 .

int compare(const path& pval) const noexcept;
int compare(const string_type& str) const;
int compare(const value_type *ptr) const;

매개 변수

pval
비교할 경로입니다.

str
비교할 문자열입니다.

ptr
비교할 포인터입니다.

path::concat

필요에 따라 지정된 시퀀스를 변환된 시퀀스에 mypath추가합니다(구분 기호를 삽입하지 않음).

template <class Source>
path& concat(const Source& source);

template <class InIt>
path& concat(InIt first, InIt last);

매개 변수

source
지정된 시퀀스입니다.

first
지정된 시퀀스의 시작입니다.

last
지정된 시퀀스의 끝입니다.

path::const_iterator

iterator의 동의어입니다.

typedef iterator const_iterator;

path::empty

mypath.empty()을(를) 반환합니다.

bool empty() const noexcept;

path::end

형식 iterator의 시퀀스 끝 반복기를 반환합니다.

iterator end() const;

path::extension

의 접미사를 반환합니다 filename().

path extension() const;

설명

다음과 같은 접미사를 filename() X 반환합니다.

점이 없는 경우 X == path(".") || X == path("..")X 접미사는 비어 있습니다.

그렇지 않은 경우 접미사가 맨 오른쪽 점으로 시작되고 해당 점을 포함합니다.

path::filename

특히 .의 myname루트 디렉터리 구성 요소를 반환합니다 empty() path() : *--end(). 구성 요소는 비어 있을 수 있습니다.

path filename() const;

path::generic_string

슬래시로 변환된 백슬래시와 함께 this->string<Elem, Traits, Alloc>(al)를 반환합니다(Windows).

template <class Elem,
    class Traits = char_traits<Elem>,
    class Alloc = allocator<Elem>>
  basic_string<Elem, Traits, Alloc>
    generic_string(const Alloc& al = Alloc()) const;

string generic_string() const;

path::generic_u16string

슬래시로 변환된 백슬래시와 함께 u16string()를 반환합니다(Windows).

u16string generic_u16string() const;

path::generic_u32string

슬래시로 변환된 백슬래시와 함께 u32string()를 반환합니다(Windows).

u32string generic_u32string() const;

path::generic_u8string

슬래시로 변환된 백슬래시와 함께 u8string()를 반환합니다(Windows).

string generic_u8string() const;

path::generic_wstring

슬래시로 변환된 백슬래시와 함께 wstring()를 반환합니다(Windows).

wstring generic_wstring() const;

path::has_extension

!extension().empty()을(를) 반환합니다.

bool has_extension() const;

path::has_filename

!filename().empty()을(를) 반환합니다.

bool has_filename() const;

path::has_parent_path

!parent_path().empty()을(를) 반환합니다.

bool has_parent_path() const;

path::has_relative_path

!relative_path().empty()을(를) 반환합니다.

bool has_relative_path() const;

path::has_root_directory

!root_directory().empty()을(를) 반환합니다.

bool has_root_directory() const;

path::has_root_name

!root_name().empty()을(를) 반환합니다.

bool has_root_name() const;

path::has_root_path

!root_path().empty()을(를) 반환합니다.

bool has_root_path() const;

path::has_stem

!stem().empty()을(를) 반환합니다.

bool has_stem() const;

path::is_absolute

Windows의 경우 함수는 .를 반환합니다 has_root_name() && has_root_directory(). POSIX의 경우 함수는 .를 반환합니다 has_root_directory().

bool is_absolute() const;

path::is_relative

!is_absolute()을(를) 반환합니다.

bool is_relative() const;

path::iterator

의 경로 구성 요소를 지정하는 양방향 상수 반복기입니다 myname.

class iterator
   {
   // bidirectional iterator for path
   typedef bidirectional_iterator_tag iterator_category;
   typedef path_type value_type;
   typedef ptrdiff_t difference_type;
   typedef const value_type *pointer;
   typedef const value_type& reference;
   // ...
   };

설명

이 클래스는 시퀀스의 구성 요소를 지정 path 하는 양방향 상수 반복기를 설명합니다 myname .

  1. 루트 이름(있는 경우)

  2. 루트 디렉터리(있는 경우)

  3. 부모 path디렉터리 요소의 re기본ing 디렉터리 요소(있는 경우) 파일 이름으로 끝납니다(있는 경우).

형식 path개체의 경우pval:

  1. path::iterator X = pval.begin() 는 경로 이름의 첫 번째 path 요소(있는 경우)를 지정합니다.

  2. X == pval.end()Xtrue 요소가 구성 요소 시퀀스의 끝을 지나면 입니다.

  3. *X 는 현재 구성 요소와 일치하는 문자열을 반환합니다.

  4. ++X는 시퀀스에서 다음 구성 요소(있는 경우)를 지정합니다.

  5. --X는 시퀀스에서 이전 구성 요소(있는 경우)를 지정합니다.

  6. 변경하면 myname .의 요소를 지정하는 모든 반복기가 무효화됩니다 myname.

path::make_preferred

필요에 따라 각 구분 기호를 변환 preferred_separator 합니다.

path& make_preferred();

path::native

경로의 네이티브 문자열 표현을 가져옵니다.

const string_type& native() const noexcept;

설명

경로는 이식 가능한 제네릭 형식(참조 generic_string()) 또는 경로의 네이티브 형식으로 사용할 수 있습니다. 이 함수는 네이티브 문자열을 반환합니다. POSIX 시스템에서는 제네릭 형식과 네이티브 형식이 동일합니다.

Windows 11에서 실행되는 다음 예제에서 제네릭 경로 문자열은 네이티브 문자열입니다 c:/t/temp/temp.txt . c:\\t\\temp.txt

// Compile with /std:c++17 or higher
#include <filesystem>

int main()
{
    std::filesystem::path p(R"(c:\t\temp.txt)");
    auto native = p.native(); // Windows: L"c:\\t\temp.txt"
    auto generic = p.generic_string(); // Windows: "c:/t/temp.txt"
}

path::operator=

경로의 요소를 다른 경로의 복사본으로 바꿉니다.

path& operator=(const path& right);
path& operator=(path&& right) noexcept;

template <class Source>
path& operator=(const Source& source);

매개 변수

right
path 복사되는 항목입니다 path.

source
소스 path입니다.

설명

첫 번째 멤버 연산자가 .에 myname복사합니다.right.myname 두 번째 멤버 연산자는 .로 myname이동합니다right.myname. 세 번째 멤버 연산자는 *this = path(source).

path::operator+=

다양한 concat 식입니다.

path& operator+=(const path& right);
path& operator+=(const string_type& str);
path& operator+=(const value_type *ptr);
path& operator+=(value_type elem);

template <class Source>
path& operator+=(const Source& source);

template <class Elem>
path& operator+=(Elem elem);

매개 변수

right
추가된 경로입니다.

str
추가된 문자열입니다.

ptr
추가된 포인터입니다.

elem
추가 value_type 된 또는 Elem.

source
추가된 원본입니다.

설명

멤버 함수는 다음 해당 식과 동일하게 작동합니다.

  1. concat(right);

  2. concat(path(str));

  3. concat(ptr);

  4. concat(string_type(1, elem));

  5. concat(source);

  6. concat(path(basic_string<Elem>(1, elem)));

path::operator/=

다양한 append 식입니다.

path& operator/=(const path& right);

template <class Source>
path& operator/=(const Source& source);

매개 변수

right
추가된 경로입니다.

source
추가된 원본입니다.

설명

멤버 함수는 다음 해당 식과 동일하게 작동합니다.

  1. append(right);

  2. append(source);

path::operator string_type

myname을(를) 반환합니다.

operator string_type() const;

path::parent_path

의 부모 경로 구성 요소를 반환합니다 myname.

path parent_path() const;

설명

특히 제거 filename().native() 후의 myname접두사 및 바로 앞에 있는 디렉터리 구분 기호의 myname 부모 경로 구성 요소를 반환합니다. (마찬가지로, 이 경우 begin() != end()연속적으로 적용하여 범위 [begin(), --end()) 의 모든 요소를 결합하는 operator/=것입니다.) 구성 요소가 비어 있을 수 있습니다.

path::path

다양한 방법으로 생성 path 합니다.

path();

path(const path& right);
path(path&& right) noexcept;

template <class Source>
path(const Source& source);

template <class Source>
path(const Source& source, const locale& loc);

template <class InIt>
path(InIt first, InIt last);

template <class InIt>
path(InIt first, InIt last, const locale& loc);

매개 변수

right
생성된 경로가 복사본이 될 경로입니다.

source
생성된 경로가 복사본이 될 원본입니다.

loc
지정된 로캘입니다.

first
복사할 첫 번째 요소의 위치입니다.

last
복사할 마지막 요소의 위치입니다.

설명

생성자는 모두 다양한 방법으로 생성 myname 합니다.

path() 입니다 myname().

의 경우 path(const path& right입니다 myname(right.myname).

path(path&& right) 입니다 myname(right.myname).

template<class Source> path(const Source& source) 입니다 myname(source).

myname(source)의 경우 template<class Source> path(const Source& source, const locale& loc) 필요한 codecvt 패싯을 loc가져옵니다.

template<class InIt> path(InIt first, InIt last) 입니다 myname(first, last).

myname(first, last)의 경우 template<class InIt> path(InIt first, InIt last, const locale& loc) 필요한 codecvt 패싯을 loc가져옵니다.

path::preferred_separator

상수 개체는 호스트 운영 체제에 따라 경로 구성 요소를 구분하는 기본 문자를 제공합니다.

#if _WIN32_C_LIB
static constexpr value_type preferred_separator == L'\\';
#else // assume POSIX
static constexpr value_type preferred_separator == '/';
#endif // filesystem model now defined

설명

Windows의 대부분의 컨텍스트에서 해당 위치에서 사용할 L'/' 수 있습니다.

path::relative_path

의 상대 경로 구성 요소를 반환합니다 myname.

path relative_path() const;

설명

특히 제거 root_path().native() 후의 접미사 및 즉시 후속 중복 디렉터리 구분 기호의 myname 상대 경로 구성 요소를 myname반환합니다. 구성 요소는 비어 있을 수 있습니다.

path::remove_filename

파일 이름을 제거합니다.

path& remove_filename();

path::replace_extension

의 확장을 myname바꿉니다.

path& replace_extension(const path& newext = path());

매개 변수

newext
새 확장입니다.

설명

먼저 .에서 myname접미사를 extension().native() 제거합니다. !newext.empty() && newext[0] != dot 그런 다음 점이 있는 경우 *path(".").c_str()이 .에 myname추가됩니다. 그런 다음 newext , 에 myname추가됩니다.

path::replace_filename

파일 이름을 바꿉니다.

path& replace_filename(const path& pval);

매개 변수

pval
파일 이름의 경로입니다.

설명

멤버 함수에서 다음을 실행합니다.

remove_filename();

*this /= pval;
return (*this);

path::root_directory

의 루트 디렉터리 구성 요소를 myname반환합니다.

path root_directory() const;

설명

구성 요소는 비어 있을 수 있습니다.

path::root_name

의 루트 이름 구성 요소를 반환합니다 myname.

path root_name() const;

설명

구성 요소는 비어 있을 수 있습니다.

path::root_path

의 루트 경로 구성 요소를 반환합니다 myname.

path root_path() const;

설명

특히 .의 myname루트 경로 구성 요소를 반환합니다 root_name() / root_directory. 구성 요소는 비어 있을 수 있습니다.

path::stem

stem 구성 요소를 반환합니다 myname.

path stem() const;

설명

특히 filename().native() 후행이 stem 제거된 구성 요소를 myname반환합니다extension().native(). 구성 요소는 비어 있을 수 있습니다.

path::string

에 저장된 시퀀스를 변환합니다 mypath.

template \<class Elem, class Traits = char_traits\<Elem>, class Alloc = allocator\<Elem>>
basic_string\<Elem, Traits, Alloc> string(const Alloc& al = Alloc()) const;
string string() const;

설명

첫 번째(템플릿) 멤버 함수는 다음과 같은 방식으로 저장된 mypath 시퀀스를 변환합니다.

  1. string<char, Traits, Alloc>()의 경우 string()

  2. string<wchar_t, Traits, Alloc>()의 경우 wstring()

  3. string<char16_t, Traits, Alloc>()의 경우 u16string()

  4. string<char32_t, Traits, Alloc>()의 경우 u32string()

두 번째 멤버 함수는 시 mypath 퀀스에 대해 호스트 시스템에서 char 선호하는 인코딩으로 저장된 시퀀스를 변환하고 형식 string의 개체에 저장된 시퀀스를 반환합니다.

path::string_type

이 형식은 basic_string<value_type>의 동의어입니다.

typedef basic_string<value_type> string_type;

path::swap

를 실행합니다.swap(mypath, right.mypath)

void swap(path& right) noexcept;

path::u16string

저장된 mypath 시퀀스를 UTF-16으로 변환하고 형식 u16string의 개체에 저장된 시퀀스를 반환합니다.

u16string u16string() const;

path::u32string

저장된 mypath 시퀀스를 UTF-32로 변환하고 형식 u32string의 개체에 저장된 시퀀스를 반환합니다.

u32string u32string() const;

path::u8string

저장된 mypath 시퀀스를 UTF-8로 변환하고 형식 u8string의 개체에 저장된 시퀀스를 반환합니다.

string u8string() const;

path::value_type

이 형식은 호스트 운영 체제에서 선호하는 요소를 설명 path 합니다.

#if _WIN32_C_LIB
typedef wchar_t value_type;
#else // assume POSIX
typedef char value_type;
#endif // filesystem model now defined

path::wstring

시퀀스에 대해 호스트 시스템에서 wchar_t 선호하는 인코딩으로 저장된 mypath 시퀀스를 변환하고 형식wstring의 개체에 저장된 시퀀스를 반환합니다.

wstring wstring() const;

참고 항목

헤더 파일 참조