It assigns a new value to the string, replacing its current contents.
Following is the declaration for std::string::operator=
tring& operator= (const string& str);
str − It is an another string object.
s − Pointer to an array of characters.
c − Character to fill the string.
il − It is an initializer_list object.
It returns *this.
Never throw any exceptions.
In below example for std::string::operator=.
#include <string> int main () { std::string str1, str2, str3; str1 = "Test string: "; str2 = 'abc'; str3 = str1 + str2; std::cout << str3 << '\n'; return 0; }
The sample output should be like this −
Test string: c