Some excerpts from the standard first:
Spec for string::operator[]():
const_reference operator [] (size_type pos) const;
reference operator [] (size_type pos);
Requires : pos <= size ().
Returns : * (begin () + pos) if pos <size (), otherwise a reference to an object of type T with value charT (); the reference value should not be modified.
Difficulty : constant time.
Spec for string::c_str()and string::data():
const charT * c_str () const noexcept;
const charT * data () const noexcept;
Returns : a pointer p such that p + i == &operator[](i)for each I am in [0, size ()].
Complexity : constant time.
2 , , p, c_str()/data(), , p[0...size()-1] , p[size()] operator[](size()), charT(). charT(), ( charT() ). , ++ 11 , str::string ?
. , , . , , , .
, : std::string charT() c_str()/data() . (.. size()+1 .)