Append Operators

◀ Test for String Equality▶ The append() Function
Amazon There are many situations where you want to append a string to another string, also known as concatenation. You can use += operator, which lets you append a string, a char array, or a character to another string, as the following prototypes show:

string & operator+=(const string & s);
string & operator+=(const char *cs);
string & operator+=(char c);

Here are several examples:

string a = “intentions ”;
string b = “speak louder than ”;

char *c = “actions”;
char d = ‘d’;
a = a + b; /* a is “intentions speak louder than ” */
a = a + c; /* a is “intentions speak louder than actions” */
a = “intentions ”;
a = a + d; /* a is “intentions d” */

Using the + operator to concatenate a string to another string feels natural.

Next we’ll explore doing similar tasks with append() functions!
◀ Test for String Equality▶ The append() Function

fShare
Questions? Let me know!