basic_string::append
文字列の末尾に文字を追加します。
basic_string<CharType, Traits, Allocator>& append(
const value_type* _Ptr
);
basic_string<CharType, Traits, Allocator>& append(
const value_type* _Ptr,
size_type _Count
);
basic_string<CharType, Traits, Allocator>& append(
const basic_string<CharType, Traits, Allocator>& _Str,
size_type _Off,
size_type _Count
);
basic_string<CharType, Traits, Allocator>& append(
const basic_string<CharType, Traits, Allocator>& _Str
);
basic_string<CharType, Traits, Allocator>& append(
size_type _Count,
value_type _Ch
);
template<class InputIterator>
basic_string<CharType, Traits, Allocator>& append(
InputIterator _First,
InputIterator _Last
);
basic_string<CharType, Traits, Allocator>& append(
const_pointer _First,
const_pointer _Last
);
basic_string<CharType, Traits, Allocator>& append(
const_iterator _First,
const_iterator _Last
);
パラメーター
_Ptr
追加する C 文字列。_Str
The string 文字を追加する。_Off
追加する文字を指定しているソースの文字列の一部のインデックス。_Count
元の文字列から、最大で、追加する文字数。_Ch
追加する文字の値。_First
追加する範囲内の先頭の要素を示す入力反復子。_Last
追加する範囲の最後の要素の次の項目の位置を示す入力反復子 const_pointer、または const_iterator。
戻り値
メンバー関数で渡される文字が付加される文字列オブジェクトへの参照。
解説
文字は operator+= またはメンバー関数 append か push_backを使用して文字列に追加される場合があります。operator+= は複数の引数 append のメンバー関数が文字列がの特定の部分を追加することで指定されるようになりますが、単一引数の値を追加します。
使用例
// basic_string_append.cpp
// compile with: /EHsc
#include <string>
#include <iostream>
int main( )
{
using namespace std;
// The first member function
// appending a C-string to a string
string str1a ( "Hello " );
cout << "The original string str1 is: " << str1a << endl;
const char *cstr1a = "Out There ";
cout << "The C-string cstr1a is: " << cstr1a << endl;
str1a.append ( cstr1a );
cout << "Appending the C-string cstr1a to string str1 gives: "
<< str1a << "." << endl << endl;
// The second member function
// appending part of a C-string to a string
string str1b ( "Hello " );
cout << "The string str1b is: " << str1b << endl;
const char *cstr1b = "Out There ";
cout << "The C-string cstr1b is: " << cstr1b << endl;
str1b.append ( cstr1b , 3 );
cout << "Appending the 1st part of the C-string cstr1b "
<< "to string str1 gives: " << str1b << "."
<< endl << endl;
// The third member function
// appending part of one string to another
string str1c ( "Hello " ), str2c ( "Wide World " );
cout << "The string str2c is: " << str2c << endl;
str1c.append ( str2c , 5 , 5 );
cout << "The appended string str1 is: "
<< str1c << "." << endl << endl;
// The fourth 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;
// The fifth member function
// appending characters to a string
string str1e ( "Hello " );
str1e.append ( 4 , '!' );
cout << "The string str1 appended with exclamations is: "
<< str1e << endl << endl;
// The sixth member function
// appending a range of one string to another
string str1f ( "Hello " ), str2f ( "Wide World " );
cout << "The string str2f is: " << str2f << endl;
str1f.append ( str2f.begin ( ) + 5 , str2f.end ( ) - 1 );
cout << "The appended string str1 is: "
<< str1f << "." << endl << endl;
}
必要条件
ヘッダー: <string>
名前空間: std