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\n";
if(memcmp(cstr, s1.data(), s1.length()) == 0)
cout << "the same content\n";
}
return 0;
}