std::filesystem::path::append, std::filesystem::path::operator/=
提供: cppreference.com
<tbody>
</tbody>
path& operator/=(const path& p); |
(1) | (C++17以上) |
template< class Source > path& operator/=( const Source& source ); |
(2) | (C++17以上) |
template< class Source > path& append( const Source& source ); |
(3) | (C++17以上) |
template< class InputIt > path& append( InputIt first, InputIt last ); |
(4) | (C++17以上) |
1)
p.is_absolute() || (p.has_root_name() && p.root_name() != root_name()) であれば、 operator=(p) によって行われたかのように、現在のパスを p で置き換え、処理を終えます。 * そうでなく、
p.has_root_directory() であれば、 *this の汎用形式のパス名から、あらゆるルートディレクトリと相対パス全体を削除します。 * そうでなく、
has_filename() || (!has_root_directory() && is_absolute()) であれば、 *this の汎用形式に path::preferred_separator を追加します。 * いずれの場合でも、その後、
p のネイティブ形式のパス名を、その汎用形式からあらゆるルート名を削除して、 *this のネイティブ形式に追加します。// where "//host" is a root-name
path("//host") / "foo" // the result is "//host/foo" (appends with separator)
path("//host/") / "foo" // the result is also "//host/foo" (appends without separator)
// On POSIX,
path("foo") / "" // the result is "foo/" (appends)
path("foo") / "/bar"; // the result is "/bar" (replaces)
// On Windows,
path("foo") / "C:/bar"; // the result is "C:/bar" (replaces)
path("foo") / "C:"; // the result is "C:" (replaces)
path("C:") / ""; // the result is "C:" (appends, without separator)
path("C:foo") / "/bar"; // yields "C:/bar" (removes relative path, then appends)
path("C:foo") / "C:bar"; // yields "C:foo/bar" (appends, omitting p's root-name)
2,3) (1) と同じですが、任意の std::basic_string、 std::basic_string_view、ヌル終端文字列、またはヌル終端文字シーケンスを指す入力イテレータを取ります。
return operator/=(path(source)); と同等です。4) (1) と同じですが、文字列を表す任意のイテレータの組を取ります。
return operator/=(path(first, last)); と同等です。引数
| p | - | 追加するパス名 |
| source | - | 移植性のある形式かネイティブ形式のいずれかでパス名を表す std::basic_string、 std::basic_string_view、ヌル終端文字列、またはヌル終端文字シーケンスを指す入力イテレータ |
| first, last | - | パス名を表す文字シーケンスを指定する一組の LegacyInputIterator |
| 型の要件 | ||
-InputIt は LegacyInputIterator の要件を満たさなければなりません。
| ||
-InputIt の値型はエンコードされた文字型 (char, wchar_t, char16_t, char32_t) のいずれかでなければなりません。
|
戻り値
*this。
例外
メモリ確保に失敗した場合は std::bad_alloc を投げる可能性があります。
ノート
これらの関数は実質的に *this を開始ディレクトリとする環境における引数のパス p の意味の近似を生成します。
例
Run this code
#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';
}
出力例:
"C:" / "Users" == "C:Users"
"C:" / "Users" / "batman" == "C:Users\\batman"
関連項目
| ディレクトリ区切り文字を付けずに2つのパスを連結します (パブリックメンバ関数) | |
| 2つのパスをディレクトリ区切り文字付きで連結します (関数) |