Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Veranschaulicht, wie die Funktion basic_string::Add an Standardvorlagenbibliothek (STL) in Visual C++ verwendet.
string& append(
const basic_string& _X
);
string& append(
const basic_string& _X,
size_type pos,
size_type count
);
string& append(
const element_type *_S,
size_type count
);
string& append(
const element_type *_S
);
string& append(
size_type count,
element_type _C
);
string& append(
Iterator first,
Iterator last
);
Hinweise
Hinweis |
|---|
Die Klasse/Parameternamen im Prototyp stimmen nicht mit der Version in der Headerdatei ab.Einige wurden geändert, um die Lesbarkeit zu verbessern. |
Die append-Memberfunktionen der basic_string::append-Elemente am Ende der Zeichenfolge.Die verschiedenen Formen der Funktion bieten alternative Methoden, die die Quelle der Elemente anzugeben, die angefügt werden.Die append-Funktionen geben einen Verweis auf die Zeichenfolge zurück, in der die Elemente angefügt wurden.
Beispiel
// bsappend.cpp
// compile with: /EHsc
//
// Functions:
// string::append - appends a sequence of elements to the
// current string.
//////////////////////////////////////////////////////////////////////
#include <string>
#include <iostream>
using namespace std ;
int main()
{
string str1("012");
string str2("345");
cout << "str1 = " << str1.c_str() << endl;
// append str2 to str1
str1.append(str2);
cout << "str1 = " << str1.c_str() << endl;
// append the last 2 items in str2 to str1
str2 = "567";
str1.append(str2, 1, 2); // begin at pos 1, append 2 elements
cout << "str1 = " << str1.c_str() << endl;
// append the first 2 items from an array of the element type
char achTest[] = {'8', '9', 'A'};
str1.append(achTest, 2);
cout << "str1 = " << str1.c_str() << endl;
// append all of a string literal to str1
char szTest[] = "ABC";
str1.append(szTest);
cout << "str1 = " << str1.c_str() << endl;
// append one item of the element type
str1.append(1, 'D');
cout << "str1 = " << str1.c_str() << endl;
// append str2 to str1 using iterators
str2 = "EF";
str1.append (str2.begin(), str2.end());
cout << "str1 = " << str1.c_str() << endl;
}
Output
str1 = 012
str1 = 012345
str1 = 01234567
str1 = 0123456789
str1 = 0123456789ABC
str1 = 0123456789ABCD
str1 = 0123456789ABCDEF
Anforderungen
Header: <string>
Hinweis