What is the difference between string::at and string::operator[]?

Yes, there is one major difference: using .at() does a range check on index passed and throws an exception if it’s over the end of the string while operator[] just brings undefined behavior in that situation.

Leave a Comment