What's the difference between std::string::c_str and std::string::data? [duplicate]
问题 This question already has answers here : string c_str() vs. data() (6 answers) Closed 5 years ago . 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... 回答1: c_str() guarantees NUL termination. data() does not. 回答2: 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