GeezerVison is showing cpprefjp.github.io — std::basic_string::operator+= - cpprefjp C++日本語リファレンス
最終更新日時:
2026年08月25日 12時11分17秒 (JST)
Akira Takahashi
が更新
履歴
編集
function
<string>
std:: basic_string:: operator+=
basic_string & operator += ( const basic_string & str ); // (1) C++98
constexpr basic_string & operator += ( const basic_string & str ); // (1) C++20
basic_string & operator += ( const charT * s ); // (2) C++98
constexpr basic_string & operator += ( const charT * s ); // (2) C++20
basic_string & operator += ( charT c ); // (3) C++98
constexpr basic_string & operator += ( charT c ); // (3) C++20
basic_string & operator += ( initializer_list < charT > il ); // (4) C++11
constexpr basic_string & operator += ( initializer_list < charT > il ); // (4) C++20
// string_view を引数に取るオーバーロード
template < class T >
basic_string & operator += ( const T & t ); // (5) C++17
template < class T >
constexpr basic_string & operator += ( const T & t ); // (5) C++20
概要
指定された文字列、文字、あるいは初期化リストを追加する。
テンプレートパラメータ制約
要件
(3) : s は少なくとも traits_type::length(s) + 1 の長さを持つ charT 型の配列を指していること。
効果
(1) 対象オブジェクトの末尾に str の値が追加(コピー)される。
append (str) と等価。
(2) 対象オブジェクトの末尾に s から始まる NULL で終端された文字列が追加される。
append (basic_string <value_type, traits_type, allocator_type>(s))(C++98 まで)、あるいは、append (s)(C++11 から)と等価。
なお、s から始まる NULL 終端された文字列の長さは、traits_type::length(s) で求められる。
(3) 対象オブジェクトの末尾に文字 c が追加される。
append (basic_string <value_type, traits_type, allocator_type>(1, c)) と等価。
(4) 対象オブジェクトの末尾に初期化リスト il で表された文字列が追加される。
append (il) と等価。
(5) 対象オブジェクトの末尾にbasic_string_view <charT, traits>に変換可能なtの参照する文字列が追加される。
以下と等価。
戻り値
*this
例外
備考
本メンバ関数の呼び出しによって、対象オブジェクトの要素への参照、ポインタ、および、イテレータは無効になる可能性がある。
例
出力
Hello
Hello,
Hello, world
Hello, world!
Hello, world! :)
Hello, world! :) :)
関連項目
参照