Is there any rules in the standard that violates modifications of internal std::string buffer returned by operator[] like this:
void foo(char* buf)
{
buf[1] = 's';
}
std::string str = "str";
modify_buffer(&str[0]);
I found the following quote in the C++11 draft about data and c_str functions:
Requires: The program shall not alter any of the values stored in the character array.
But I don't see any about operator[].
std::stringin your example.data()andc_str()returnsconst char*operator[]then why do you think a pointer to the element would be any different?