basic_string::operator+=

文字列に文字を追加します。

basic_string<CharType, Traits, Allocator>& operator+=(
   value_type _Ch
);
basic_string<CharType, Traits, Allocator>& operator+=(
   const value_type* _Ptr
);
basic_string<CharType, Traits, Allocator>& operator+=(
   const basic_string<CharType, Traits, Allocator>& _Right
);

パラメーター

  • _Ch
    追加する文字。

  • _Ptr
    付けられる C 文字列の文字。

  • _Right
    追加する文字列の文字。

戻り値

文字が付けられた文字列オブジェクトへの参照がメンバー関数を合格しました。

解説

文字は operator+= またはメンバー関数 追加 または push_backを使用して文字列に付けられている可能性があります。 operator+= は複数の引数が追加で指定された文字列の特定の部分メンバー関数の許可を付けるときに、単一の引数値を追加します。

使用例

// basic_string_op_app.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;

   // The first member function
   // appending a single character to a string
   string str1a ( "Hello" );
   cout << "The original string str1 is: " << str1a << endl;
   str1a +=  '!' ;
   cout << "The string str1 appended with an exclamation is: " 
        << str1a << endl << endl;

   // The second member function
   // appending a C-string to a string
   string  str1b ( "Hello " );
   const char *cstr1b = "Out There";
   cout << "The C-string cstr1b is: " << cstr1b << endl;
   str1b +=  cstr1b;
   cout << "Appending the C-string cstr1b to string str1 gives: " 
        << str1b << "." << endl << endl;

   // The third member function
   // appending one string to another in two ways,
   // comparing append and operator [ ]
   string str1d ( "Hello " ), str2d ( "Wide " ), str3d ( "World" );
   cout << "The string str2d is: " << str2d << endl;
   str1d.append ( str2d );
   cout << "The appended string str1d is: " 
        << str1d << "." << endl;
   str1d += str3d;
   cout << "The doubly appended strig str1 is: " 
        << str1d << "." << endl << endl;
}
  

必要条件

ヘッダー: の <文字列>

名前空間: std

参照

関連項目

basic_string クラス