[fs.class.path.general]

# 31 Input/output library [[input.output]](./#input.output)

## 31.12 File systems [[filesystems]](filesystems#fs.class.path.general)

### 31.12.6 Class path [[fs.class.path]](fs.class.path#general)

#### 31.12.6.1 General [fs.class.path.general]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13559)

An object of class path represents a path
and contains a pathname[.](#1.sentence-1)

Such an object is concerned only with the lexical and syntactic aspects
of a path[.](#1.sentence-2)

The path does not necessarily exist in external storage, and the
pathname is not necessarily valid for the current operating
system or for a particular file system[.](#1.sentence-3)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13567)

[*Note [1](#note-1)*:

Class path is used to support the differences
between the string types used by different operating systems
to represent pathnames,
and to perform conversions between encodings when necessary[.](#2.sentence-1)

â *end note*]

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13575)

A [*path*](#def:path "31.12.6.1 General [fs.class.path.general]") is
a sequence of elements that identify
the location of a file within a filesystem[.](#3.sentence-1)

The elements are the[*root-name*](fs.path.generic#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]")opt,[*root-directory*](fs.path.generic#nt:root-directory "31.12.6.2 Generic pathname format [fs.path.generic]")opt,
and an optional sequence of [*filename*](fs.path.generic#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]")*s* ([[fs.path.generic]](fs.path.generic "31.12.6.2 Generic pathname format"))[.](#3.sentence-2)

The maximum number of elements in the sequence is
operating system dependent ([[fs.conform.os]](fs.conform.os "31.12.2.3 Operating system dependent behavior conformance"))[.](#3.sentence-3)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13586)

An [*absolute path*](#def:path,absolute "31.12.6.1 General [fs.class.path.general]") is a path that unambiguously
identifies the location of a file without reference to an additional starting
location[.](#4.sentence-1)

The elements of a path that determine if it is absolute are
operating system dependent[.](#4.sentence-2)

A [*relative path*](#def:path,relative "31.12.6.1 General [fs.class.path.general]") is
a path that is not absolute, and as such, only unambiguously
identifies the location of a file when resolved relative to
an implied starting location[.](#4.sentence-3)

The elements of a path that determine if it is
relative are operating system dependent[.](#4.sentence-4)

[*Note [2](#note-2)*:

Pathnames â.â and â..â are relative paths[.](#4.sentence-5)

â *end note*]

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13600)

A [*pathname*](#def:pathname "31.12.6.1 General [fs.class.path.general]") is
a character string that represents the name of a path[.](#5.sentence-1)

Pathnames are
formatted according to the generic pathname format grammar ([[fs.path.generic]](fs.path.generic "31.12.6.2 Generic pathname format"))
or according to an
operating system dependent[*native pathname format*](#def:native_pathname_format "31.12.6.1 General [fs.class.path.general]") accepted by the host operating system[.](#5.sentence-2)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13608)

[*Pathname resolution*](#def:pathname_resolution "31.12.6.1 General [fs.class.path.general]") is the operating system dependent mechanism for resolving
a pathname to a particular file in a file hierarchy[.](#6.sentence-1)

There may be multiple
pathnames that resolve to the same file[.](#6.sentence-2)

[*Example [1](#example-1)*:

For POSIX-based operating systems,
this mechanism is specified in POSIX, section 4.12, Pathname resolution[.](#6.sentence-3)

â *end example*]

namespace std::filesystem {class path {public:using value_type = *see below*; using string_type = basic_string<value_type>; static constexpr value_type preferred_separator = *see below*; // [[fs.enum.path.format]](fs.enum.path.format "31.12.8.1 Enum path​::​format"), enumeration formatenum format; // [[fs.path.construct]](fs.path.construct "31.12.6.5.1 Constructors"), constructors and destructor path() noexcept;
 path(const path& p);
 path(path&& p) noexcept;
 path(string_type&& source, format fmt = auto_format); template<class Source> path(const Source& source, format fmt = auto_format); template<class InputIterator> path(InputIterator first, InputIterator last, format fmt = auto_format); template<class Source> path(const Source& source, const locale& loc, format fmt = auto_format); template<class InputIterator> path(InputIterator first, InputIterator last, const locale& loc, format fmt = auto_format); ~path(); // [[fs.path.assign]](fs.path.assign "31.12.6.5.2 Assignments"), assignments path& operator=(const path& p);
 path& operator=(path&& p) noexcept;
 path& operator=(string_type&& source);
 path& assign(string_type&& source); template<class Source> path& operator=(const Source& source); template<class Source> path& assign(const Source& source); template<class InputIterator> path& assign(InputIterator first, InputIterator last); // [[fs.path.append]](fs.path.append "31.12.6.5.3 Appends"), appends path& operator/=(const path& p); template<class Source> path& operator/=(const Source& source); template<class Source> path& append(const Source& source); template<class InputIterator> path& append(InputIterator first, InputIterator last); // [[fs.path.concat]](fs.path.concat "31.12.6.5.4 Concatenation"), concatenation path& operator+=(const path& x);
 path& operator+=(const string_type& x);
 path& operator+=(basic_string_view<value_type> x);
 path& operator+=(const value_type* x);
 path& operator+=(value_type x); template<class Source> path& operator+=(const Source& x); template<class EcharT> path& operator+=(EcharT x); template<class Source> path& concat(const Source& x); template<class InputIterator> path& concat(InputIterator first, InputIterator last); // [[fs.path.modifiers]](fs.path.modifiers "31.12.6.5.5 Modifiers"), modifiersvoid clear() noexcept;
 path& make_preferred();
 path& remove_filename();
 path& replace_filename(const path& replacement);
 path& replace_extension(const path& replacement = path()); void swap(path& rhs) noexcept; // [[fs.path.nonmember]](fs.path.nonmember "31.12.6.8 Non-member functions"), non-member operatorsfriend bool operator==(const path& lhs, const path& rhs) noexcept; friend strong_ordering operator<=>(const path& lhs, const path& rhs) noexcept; friend path operator/(const path& lhs, const path& rhs); // [[fs.path.native.obs]](fs.path.native.obs "31.12.6.5.6 Native format observers"), native format observersconst string_type& native() const noexcept; const value_type* c_str() const noexcept; operator string_type() const; template<class EcharT, class traits = char_traits<EcharT>, class Allocator = allocator<EcharT>> basic_string<EcharT, traits, Allocator> string(const Allocator& a = Allocator()) const;
 std::string display_string() const;
 std::string system_encoded_string() const;
 std::wstring wstring() const;
 std::u8string u8string() const;
 std::u16string u16string() const;
 std::u32string u32string() const; // [[fs.path.generic.obs]](fs.path.generic.obs "31.12.6.5.7 Generic format observers"), generic format observerstemplate<class EcharT, class traits = char_traits<EcharT>, class Allocator = allocator<EcharT>> basic_string<EcharT, traits, Allocator> generic_string(const Allocator& a = Allocator()) const;
 std::string generic_display_string() const;
 std::string generic_system_encoded_string() const;
 std::wstring generic_wstring() const;
 std::u8string generic_u8string() const;
 std::u16string generic_u16string() const;
 std::u32string generic_u32string() const; // [[fs.path.compare]](fs.path.compare "31.12.6.5.8 Compare"), compareint compare(const path& p) const noexcept; int compare(const string_type& s) const; int compare(basic_string_view<value_type> s) const; int compare(const value_type* s) const; // [[fs.path.decompose]](fs.path.decompose "31.12.6.5.9 Decomposition"), decomposition path root_name() const;
 path root_directory() const;
 path root_path() const;
 path relative_path() const;
 path parent_path() const;
 path filename() const;
 path stem() const;
 path extension() const; // [[fs.path.query]](fs.path.query "31.12.6.5.10 Query"), querybool empty() const noexcept; bool has_root_name() const; bool has_root_directory() const; bool has_root_path() const; bool has_relative_path() const; bool has_parent_path() const; bool has_filename() const; bool has_stem() const; bool has_extension() const; bool is_absolute() const; bool is_relative() const; // [[fs.path.gen]](fs.path.gen "31.12.6.5.11 Generation"), generation path lexically_normal() const;
 path lexically_relative(const path& base) const;
 path lexically_proximate(const path& base) const; // [[fs.path.itr]](fs.path.itr "31.12.6.6 Iterators"), iteratorsclass iterator; using const_iterator = iterator;

 iterator begin() const;
 iterator end() const; // [[fs.path.io]](fs.path.io "31.12.6.7 Inserter and extractor"), path inserter and extractortemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const path& p); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, path& p); };}

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13775)

value_type is a typedef for the
operating system dependent encoded character type used to represent pathnames[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13780)

The value of the preferred_separator member
is the operating system dependent [*preferred-separator*](fs.path.generic#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]") character ([[fs.path.generic]](fs.path.generic "31.12.6.2 Generic pathname format"))[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13784)

[*Example [2](#example-2)*:

For POSIX-based operating systems,value_type is char andpreferred_separator is the slash character ('/')[.](#9.sentence-1)

For Windows-based operating systems,value_type is wchar_t andpreferred_separator is the backslash character (L'\\')[.](#9.sentence-2)

â *end example*]
