in document of stl strings, the part regarding operator[] in here it is mentioned that
(It is for string s, at position pos, s[pos])
Exception safety
If pos is not greater than the string length, the function never throws >exceptions (no-throw guarantee).
otherwise, it causes undefined behavior.
one interesting point is that:
If pos is equal to the string length, the function returns a reference to a >null character ('\0').(C++98)
If pos is equal to the string length, the function returns a reference to >the null character that follows the last character in the string, which >shall not be modified.(C++11)
but member function ".at" is as it says in documents:
Strong guarantee: if an exception is thrown, there are no changes in the >string.
If pos is not less than the string length, an out_of_range exception is >thrown.