An
absolute path is a path that unambiguously
identifies the location of a file without reference to an additional starting
location
. The elements of a path that determine if it is absolute are
operating system dependent
. A
relative path 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
. The elements of a path that determine if it is
relative are operating system dependent
. [
Note 2:
Pathnames “.” and “..” are relative paths
. —
end note]
A
pathname is
a character string that represents the name of a path
. Pathnames are
formatted according to the generic pathname format grammar (
[fs.path.generic])
or according to an
operating system dependent
native pathname format accepted by the host operating system
.Pathname resolution
is the operating system dependent mechanism for resolving
a pathname to a particular file in a file hierarchy
. There may be multiple
pathnames that resolve to the same file
. [
Example 1:
For POSIX-based operating systems,
this mechanism is specified in POSIX, section 4.12, Pathname resolution
. —
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;
enum format;
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();
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);
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);
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);
void 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;
friend 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);
const 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;
template<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;
int 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;
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;
bool 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;
path lexically_normal() const;
path lexically_relative(const path& base) const;
path lexically_proximate(const path& base) const;
class iterator;
using const_iterator = iterator;
iterator begin() const;
iterator end() const;
template<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);
};
}
value_type is a
typedef for the
operating system dependent encoded character type used to represent pathnames. [
Example 2:
For POSIX-based operating systems,
value_type is
char and
preferred_separator is the slash character (
'/')
. For Windows-based operating systems,
value_type is
wchar_t and
preferred_separator is the backslash character (L'\\'). —
end example]