Q:

What's the difference between std::string::c_str and std::string::data?

Why would I ever want to call std::string::data() over std::string::c_str()? Surely there is some method to the standard's madness here...

A:

c_str() guarantees NUL termination. data() does not.

A:

c_str() return a pointer to the data with a NUL byte appended so you can use the return value as a "C string".
data() returns a pointer to the data without any modifications.
Use c_str() if the code you are using assumes a string is NUL terminated (such as any function written to handle C strings).

