Legal to overwrite std::string's null terminator?

后端 未结 4 420
感动是毒
感动是毒 2020-12-01 09:11

In C++11, we know that std::string is guaranteed to be both contiguous and null-terminated (or more pedantically, terminated by charT(), which in t

4条回答
  •  眼角桃花
    2020-12-01 09:48

    LWG 2475 made this valid by editing the specification of operator[](size()) (inserted text in bold):

    Otherwise, returns a reference to an object of type charT with value charT(), where modifying the object to any value other than charT() leads to undefined behavior.

提交回复
热议问题