Accessing a single character of the string is done with operator [ ]. Note that this operator does
not check whether the index of the string is valid. Thus, the programmer has to ensure that the
index is valid, as was done here. A safer way to access a character is to use the at() member
function. However, such a check costs runtime, so the check is not provided for the usual accessing
of characters of a string.