Basic Assignment

There are three overloaded assignment methods:

basic_string&operator=(const basic_string&str);
basic_string&operator=(const charT* s);
basic_string&operator=(charT c);

The first assigns one string object to another, the second assigns a C-style string to a string object, and the third assigns a single character to a string object. Thus, all of the following operations are possible:

string name("George Wash");
string pres, veep, source;
pres = name;
veep = "Road Runner";
@CX:source = `X';
					
					
					
					
				

Get The Waite Group's C++ Primer Plus, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.