27 Input/output library [input.output]

27.10 File systems [filesystems]

27.10.8 Class path [class.path]

27.10.8.4 path members [path.member]

27.10.8.4.5 path modifiers [path.modifiers]

void clear() noexcept;

Postconditions: empty() == true.

path& make_preferred();

Effects: Each directory-separator is converted to preferred-separator.

Returns: *this.

Example:

path p("foo/bar");
std::cout << p << '\n';
p.make_preferred();
std::cout << p << '\n';

On an operating system where preferred-separator is the same as directory-separator, the output is:

"foo/bar"
"foo/bar"

On an operating system where preferred-separator is a backslash, the output is:

"foo/bar"
"foo\bar"

 — end example ]

path& remove_filename();

Postconditions: !has_filename().

Returns: *this.

Example:

std::cout << path("/foo").remove_filename();  // outputs "/"
std::cout << path("/").remove_filename();     // outputs ""

 — end example ]

path& replace_filename(const path& replacement);

Effects: Equivalent to:

remove_filename();
operator/=(replacement);

Returns: *this.

Example:

std::cout << path("/").replace_filename("bar");     // outputs "bar"

 — end example ]

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

Effects: pathstring (the stored path) is modified as follows:

  • Any existing extension()([path.decompose]) is removed from the stored path, then

  • If replacement is not empty and does not begin with a dot character, a dot character is appended to the stored path, then

  • replacement is concatenated to the stored path.

Returns: *this.

void swap(path& rhs) noexcept;

Effects: Swaps the contents of the two paths pathstring and rhs.pathstring.

Complexity: Constant time.