APPEND()
This member of the std::string class allows the addition of characters or another string to the end of an existing string. It is similar to using the += operator, but it provides more flexibility through multiple overloads. For example, you can append an entire string, a substring, a single character, or a specified number of characters from a C-style character array. Each call modifies the original string by extending its length to include the new content. It is commonly used when building or concatenating strings in a step-by-step manner.
string1.append(string2);
#include <iostream> // For input and output
#include <string>
using namespace std;
int main()
{
string str1 = "Hello, "; // First string
string str2 = "World!"; // Second string
str1.append(str2); // Append str2 to str1
cout << str1 << endl; // Print the final result
return 0; // End of program
}
Last updated