Null end is a concept that applies only to C strings; it does not apply to std::string objects - they allow you to find the size by calling size() , and do not require zero completion. However, the strings returned from the std::string c_str() function have zero completion, regardless of where the data for the std::string c_str() from.
The C ++ 11 standard describes the operator [pos] prerequisites in section 21.4.5.2:
Returns: *(begin() + pos) if pos < size() . Otherwise, a reference is returned to an object of type charT with the value charT() , where changing the object leads to undefined behavior.
Pay attention to pos < size() , not pos <= size() : the standard explicitly allows std::string objects to have zero completion.
source share