In C++11 and beyond does std::string::operator[] do bounds checking?

前端 未结 5 916
南笙
南笙 2020-12-16 10:02

I have seen many times that std::string::operator[] does not do any bounds checking. Even What is the difference between string::at and string::operator[]?, as

5条回答
  •  臣服心动
    2020-12-16 10:29

    This operator of standard containers emulates the behavior of the operator [] of ordinary arrays. So it does not make any checks. However in the debug mode the corresponding library can provide this checking.

    If you want to check the index then use member function at() instead.

提交回复
热议问题