Vector\'s new method data() provides a const and non-const version.
However string\'s data() method only provides a const version.
I th
Historically, the string data has not been const because it would prevent several common optimizations, like copy-on-write (COW). This is now, IIANM, far less common, because it behaves badly with multithreaded programs.
BTW, yes they are now required to be contiguous:
[string.require].5: The char-like objects in a basic_string object shall be stored contiguously. That is, for any basic_string object s, the identity &*(s.begin() + n) == &*s.begin() + n shall hold for all values of n such that 0 <= n < s.size().
Another reason might be to avoid code such as:
std::string ret;
strcpy(ret.data(), "whatthe...");
Or any other function that returns a preallocated char array.