The first element of the string has an index of zero, and the following elements are indexed consecutively by the positive integers, so that a string of length n has an nth element indexed by the number n - 1.
operator[] is faster than the member function at for providing read and write access to the elements of a string.
operator[] does not check whether the index passed as a parameter is valid, but the member function at does and so should be used in the validity is not certain. An invalid index (an index less that zero or greater than or equal to the size of the string) passed to the member function at throws an out_of_range Class exception. An invalid index passed to operator[] results in undefined behavior, but the index equal to the length of the string is a valid index for const strings and the operator returns the null character when passed this index.
The reference returned may be invalidated by string reallocations or modifications for the non-const strings.
When compiling with _SECURE_SCL 1, a runtime error will occur if you attempt to access an element outside the bounds of the string. See Checked Iterators for more information.