代码:

#include <iostream>
#include <string>
using namespace std;

int main()
{
	string a("hha");
	string b("hha好");
	cout<<a.size()<<endl<<b.size()<<endl;
	cout<<a.length()<<endl<<b.length()<<endl;
	//可以发现string::size() 函数的作用是计算string有多少个字节
	//一个char是一个字节(byte)=8bit ,一个汉字是两个char两个字节 
	//string::size()和string::length()的作用是一模一样的 
	return 0;
}


相关文章:

  • 2022-12-23
  • 2021-08-05
  • 2021-05-18
  • 2022-12-23
  • 2022-01-17
  • 2021-08-17
猜你喜欢
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
  • 2022-03-07
  • 2021-11-29
相关资源
相似解决方案