Assigning and Appending Strings
Assignment can be done with = or the assign() member function. Both assign a constant string and can work with another string or a char * C String. However assign() can also take extra parameters for start and length.const string s("Humpty Dumpty sat on a wall") ;This outputs
string s1,s2,s3,s4;
s1.assign(s,7,6) ; // Dumpty
cout << "s1= " << s1 << endl;
s2.assign("Once",2) ;
cout << "s2= " << s2 << endl;
s3="ZZY";
s3+= s1 += s2;
cout << "s3= " << s3 << endl;
s4="Once";
s4=s4.substr(2) ;
cout << "s4= " << s4 << end
s1= Dumpty
s2= On
s3= ZZYDumptyOn
It looks similar to substr() but with the difference that the second parameter of assign() is the length not the start position.
substr("once",2); // ce
assign("once",2); // on
Emptying Strings
You can check if a string is empty with the empty) function. There is also a function clear() which empties a string, though it was never included in the library with Microsoft Visual C++ 6.0. (Not an oversight- just to do with the timing of including clear in the std library). You can however substitute erase() instead.On the next page - An example with many functions

