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;
}

posted @ 2019-12-24 08:59  MoonXu  阅读(202)  评论(0编辑  收藏  举报