How can I get a pointer to the first element of an non-const std::string even if it is empty.
I know for sure the string has a capacity greater than one, however, simply using
&my_string.front()
triggers a "out of range iterator" assertion failure because the string is empty. Using member function
data()
doesn't fit too, because I want a pointer of type char*, not const char*. I guess I can perform a const_cast here, but that doesn't seem neat.
Is there a better way to do this?