#include <iostream>
#include <string>usingnamespace std;
int main ()
{
int length;
string str ="Test string";
char* cstr ="Test string";
if ( str.length() == strlen (cstr) )
{
cout <<"str and cstr have the same length.\n";
length = str.length();
if ( memcmp (cstr, str.data(), length ) ==0 )
cout <<"str and cstr have the same content.\n";
}
return0;
}
Output:
str and cstr have the same length.str and cstr have the same content.