
为什么c++中用string定义字符串不能使用strlen计算字符串长度呢?

关注#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string s = "hello";
cout<<strlen(s.c_str()); // string 转成 char *
return 0;
}
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string A = "Hello, world!";
cout<< A.size() <<endl;
cout<< A.length() <<endl;
}