string类中的size()函数和length()函数二者是没有区别的。返回的都是字节数,不管是否有汉字。
请看下面的程序:
#include <iostream>
#include <string>
int main()
{
using namespace std;
string str("Hello") ;
cout << "length: " << str.length() << endl ;
cout << "size: " << str.size() << endl ;
return 0 ;
}
其结果是:
length: 5
size: 5