名前空間
変種
操作

std::filesystem::path::concat, std::filesystem::path::operator+=

提供: cppreference.com
< cpp‎ | filesystem‎ | path
 
 
 
 
path& operator+=( const path& p );
(1) (C++17以上)
path& operator+=( const string_type& str );
path& operator+=( std::basic_string_view<value_type> str );
(2) (C++17以上)
path& operator+=( const value_type* ptr );
(3) (C++17以上)
template< class Source >
path& operator+=( const Source& source );
(4) (C++17以上)
template< class Source >
path& concat( const Source& source );
(5) (C++17以上)
path& operator+=( value_type x );
(6) (C++17以上)
template< class CharT >
path& operator+=( CharT x );
(7) (C++17以上)
template< class InputIt >
path& concat( InputIterator first, InputIterator last );
(8) (C++17以上)

現在のパスと引数を連結します。

1-5) ネイティブ形式で *this に格納されているパス名に path(other).native() を追加します。 これは native() の値を直接操作します。 オペレーティングシステム間で移植性がない場合があります。
6-7) return *this += std::basic_string_view(&x, 1); と同じです。
8) return *this += path(first, last); と同じです。

目次

[編集] 引数

p - 追加するパス
str - 追加する文字列または文字列ビュー
ptr - 追加するヌル終端文字列の先頭を指すポインタ
x - 追加する単一の文字
source - 移植性のある形式かネイティブ形式のいずれかでパス名を表す std::basic_stringstd::basic_string_view、ヌル終端文字列、またはヌル終端文字シーケンスを指す入力イテレータ
first, last - パス名を表す文字シーケンスを表す一組の LegacyInputIterator
型の要件
-
InputItLegacyInputIterator の要件を満たさなければなりません。
-
InputIt の値型はエンコードされた文字型 (char, wchar_t, char16_t, char32_t) のいずれかでなければなりません。
-
CharT はエンコードされた文字型 (char, wchar_t, char16_t, char32_t) のいずれかでなければなりません。

[編集] 戻り値

*this

[編集] 例外

メモリ確保に失敗した場合は std::bad_alloc を投げる可能性があります。

[編集] ノート

append()operator/= と異なり、追加のディレクトリ区切り文字が挿入されることはありません。

[編集]

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main() {
    fs::path p1; // empty path
    p1 += "var"; // does not insert a separator
    std::cout << "\"\" + \"var\" == " << p1 << '\n';
    p1 += "lib"; // does not insert a separator
    std::cout << "\"\" + \"var\" + \"lib\" == " << p1 << '\n';
}

出力:

"" + "var" == "var"
"" + "var" + "lib" == "varlib"

[編集] 欠陥報告

以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。

DR 適用先 発行時の動作 正しい動作
LWG 3055 C++17 the specification of concatenating a single character was ill-formed made well-formed

[編集] 関連項目

パスに要素をディレクトリ区切り文字付きで追加します
(パブリックメンバ関数) [edit]
2つのパスをディレクトリ区切り文字付きで連結します
(関数) [edit]