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
그 문자가 추가 되는 문자열입니다._Off
인덱스 추가할 문자를 제공 하는 원본 문자열의 일부입니다._Count
기껏해야 원본 문자열에서 추가 되는 문자의 개수입니다._Ch
추가할 문자 값을 지정 합니다._First
추가할 주소 범위의 첫 번째 요소는 입력된 반복기입니다._Last
입력된 반복기, const_pointer, 또는 const_iterator 주소 범위의 마지막 요소 바로 뒤의 위치 추가 하기.
반환 값
멤버 함수에 의해 전달 되는 문자를 추가 하 고 문자열 개체 참조입니다.
설명
사용 하 여 문자열에 문자를 추가할 수는 연산자 + = 또는 멤버 함수 추가 또는 push_back.**operator+=**여러 인수를 하는 동안 단일 인수 값 추가 추가 멤버 함수 추가 대 한 지정 된 문자열의 특정 부분을 수 있습니다.
예제
// 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