1.使用字符串string的成员函数length()求
#include <string>
#include <iostream>
using namespace std;
int main()
{
string str = “hello world!";
cout << str.length() << endl;
return 0;
}
2.使用成员函数size()求
#include <string>
#include <iostream>
using namespace std;
int main()
{
string str = "Thello world!";
cout << str.size() << endl;
return 0;
}
3.使用strlen()获取字符串长度
需要将字符串使用c_str()转换成char*类型