class path;
(since C++17)Objects of type path
represent paths on a filesystem. Only syntactic aspects of paths are handled: the pathname may represent a non-existing path or even one that is not allowed to exist on the current file system or OS.
The path name has the following syntax:
path::preferred_separator
. If this character is repeated, it is treated as a single directory separator: /usr///////lib is the same as /usr/lib.A path can be normalized by following this algorithm:
path::preferred_separator
.path::preferred_separator
.The path can be traversed element-wise via iterators returned by the begin() and end() functions, which views the path in generic format and iterates over root name, root directory, and the subsequent file name elements (directory separators are skipped except the one that identifies the root directory). If the very last element in the path is a directory separator, the last iterator will dereference to an empty element.
Calling any non-const member function of a path
invalidates all iterators referring to elements of that object.
If the OS uses a native syntax that is different from the portable generic syntax described above, library functions that are defined to accept "detected format" accept path names in both formats: a detected format argument is taken to be in the generic format if and only if it matches the generic format but is not acceptable to the operating system as a native path. On those OS where native format differs between pathnames of directories and pathnames of files, a generic pathname is treated as a directory path if it ends on a directory separator and a regular file otherwise.
In any case, the path class behaves as if it stores a pathname in the native format and automatically converts to generic format as needed (each member function specifies which format it interprets the path as).
On POSIX systems, the generic format is the native format and there is no need to distinguish or convert between them.
Paths are implicitly convertible to and from std::basic_strings, which makes it possible to use them with other file APIs.
The stream operators use std::quoted so that spaces do not cause truncation when later read by stream input operator.
Decomposition member functions (e.g. extension) return filesystem::path
objects instead of string objects as other APIs do.
value_type
character type used by the native encoding of the filesystem: char on POSIX, wchar_t on Windows string_type
std::basic_string<value_type> const_iterator
a constant LegacyInputIterator with a value_type
of path
that meets all requirements of LegacyBidirectionalIterator except that for two equal dereferenceable iterators a
and b
of type const_iterator
, there is no requirement that *a and *b refer to the same object.
It is unspecified whether const_iterator
is actually a LegacyBidirectionalIterator
iterator
const_iterator
determines how to interpret string representations of pathnames.
The following enumerators are also defined:
constexpr value_type preferred_separator
[static]
alternative directory separator which may be used in addition to the portable /. On Windows, this is the backslash character \. On POSIX, this is the same forward slash / as the portable separatorThe following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 3657 C++17hash
for path
was disabled enabled
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4