Append
#include <cassert>
#include <string>
using std::string;
void main() {
string s1; // empty
string s2; // empty
s1 += "Fred"; // From null terminated char*
s1 += 'a'; // Becomes "Freda"
s2 += s1; // Of course, s2 becomes "Freda"
// Additional append functions corresponding
// to existing constructors:
s1.append( "Hello", 4);
assert( s1 == "FredaHell" );
s1.append( 6, 'a' );
assert( s1 == "FredaHellaaaaaa" );
// Append portion of s2 that begins at the position 2
// and up to 5 characters. However, it takes less
// than 5 because the end of s2 is reached sooner:
s1.append( s2, 2, 5 ); // appends "eda"
assert( s1 == "FredaHellaaaaaaeda" );
}