Search code examples
c++stdstringc-str

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...


Solution

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