22.7 — std::string inserting

Inserting Inserting characters into an existing string can be done via the insert() function. Here’s a crazy version of insert() that allows you to insert a substring into a string at an arbitrary index: There is a flavor of insert() that inserts the first portion of a C-style string: There’s …

22.6 — std::string appending

Appending Appending strings to the end of an existing string is easy using either operator+=, append(), or push_back(). There’s also a flavor of append() that can append a substring: Operator+= and append() also have versions that work on C-style strings: There is an additional flavor of append() that works on …

27.5 — Exceptions, classes, and inheritance

Exceptions and member functions Up to this point in the tutorial, you’ve only seen exceptions used in non-member functions. However, exceptions are equally useful in member functions, and even more so in overloaded operators. Consider the following overloaded [] operator as part of a simple integer array class: int& IntArray::operator[](const …