string operator+= in C++

operator +=: It appends or(adds ) the string to the existing string. It 

returns a reference to this string.

Parameters: 

__s – The C string to append. 

Syntax:

str+=__s

For Example:

str = "abc"

str+="def"= > It adds string "def" to the string "abc".So string  becomes "abcdef".

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string str = "abc";
    str += "def";

    cout << str << "\n";
 
    return 0;
}


No comments:

Post a Comment