string::data

const char* data() const noexcept;
注:同c_str

#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string s1("hellolyy");
const char *cstr = "hellolyy";
if(s1.length() == strlen(cstr))
{
cout << "the same length ";
if(memcmp(cstr, s1.data(), s1.length()) == 0)
cout << "the same content ";
}
return 0;
}

原文地址:https://www.cnblogs.com/xpylovely/p/12089582.html