Navigation



17.7 — std::string inserting

Inserting

Inserting characters into an existing string can be done via the insert() function.

string& string::insert (size_type index, const string& str) string& string::insert (size_type index, const char* str)

Both functions insert the characters of str into the string at index Both function return *this so they can be “chained”. Both functions throw out_of_range if . . . → Read More: 17.7 — std::string inserting

17.6 — std::string appending

Appending

Appending strings to the end of an existing string is easy using either operator+=, append(), or push_back() function.

string& string::operator+= (const string& str) string& string::append (const string& str)

Both functions append the characters of str to the string. Both function return *this so they can be “chained”. Both functions throw a length_error . . . → Read More: 17.6 — std::string appending

17.5 — std::string assignment and swapping

String assignment

The easiest way to assign a value to a string is to the use the overloaded operator= function. There is also an assign() member function that duplicates some of this functionality.

string& string::operator= (const string& str) string& string::assign (const string& str) string& string::operator= (const char* str) string& string::assign (const char* str) string& . . . → Read More: 17.5 — std::string assignment and swapping