65,186
社区成员




#include <iostream>
#include <string>
using namespace 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";
}
return 0;
}
Output:
str and cstr have the same length.str and cstr have the same content.