path& operator/=(const path& p); | (1) | (since C++17) |
template< class Source > path& operator/=( const Source& source ); | (2) | (since C++17) |
template< class Source > path& append( const Source& source ); | (3) | (since C++17) |
template< class InputIt > path& append( InputIt first, InputIt last ); | (4) | (since C++17) |
this
, except if any of the following conditions is true:*this
already ends with a separator)*this
is empty, or adding it would turn a relative path to an absolute path in some other wayp
is an empty path.p.native()
begins with a directory separator.p.native()
to the pathname maintained by *this
std::basic_string
, std::basic_string_view
, null-terminated multicharacter string, or an input iterator pointing to a null-terminated multicharacter sequence.p | - | pathname to append |
source | - | std::basic_string , std::basic_string_view , null-terminated multicharacter string, or an input iterator pointing to a null-terminated multicharacter sequence, which represents a path name (either in portable or in native format) |
first, last | - | pair of InputIterator s that specify a multicharacter sequence that represents a path name |
Type requirements | ||
-
InputIt must meet the requirements of InputIterator . |
||
-The value type of InputIt must be one of the encoded character types (char , wchar_t , char16_t and char32_t ) |
*this
.
May throw filesystem_error
on underlying OS API errors or std::bad_alloc
if memory allocation fails.
#include <iostream> #include <filesystem> namespace fs = std::filesystem; int main() { fs::path p1 = "C:"; p1 /= "Users"; // does not insert a separator std::cout << "\"C:\" / \"Users\" == " << p1 << '\n'; p1 /= "batman"; // inserts fs::path::preferred_separator, '\' on Windows std::cout << "\"C:\" / \"Users\" / \"batman\" == " << p1 << '\n'; }
Possible output:
"C:" / "Users" == "C:Users" "C:" / "Users" / "batman" == "C:Users\batman"
concatenates two paths without introducing a directory separator (public member function) |
|
concatenates two paths with a directory separator (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/filesystem/path/append