string类中的size()函数和length()函数的区别?
答案:2 悬赏:60
解决时间 2021-03-04 06:20
- 提问者网友:溺爱和你
- 2021-03-03 06:51
string类中的size()函数和length()函数的区别?
最佳答案
- 二级知识专家网友:舊物识亽
- 2021-03-03 07:58
都是表示字符串中的元素数,等于begin()到end()之间的距离.
length()是考虑到传统C函数strlen而对应设置的,而size()是考虑到string作为一个STL容器,应该具有的common member.
length()是考虑到传统C函数strlen而对应设置的,而size()是考虑到string作为一个STL容器,应该具有的common member.
全部回答
- 1楼网友:不如潦草
- 2021-03-03 09:07
size
语法:
size_type size();
size()函数返回字符串中现在拥有的字符数。
长度(length)
语法:
size_type length();
length()函数返回字符串的长度. 这个数字应该和size()返回的数字相同.
Actually, they have equal results, but semantics is different.
size() act as a method of container, like vector ,set and so forth.
length() represent a property of sequence
.
语法:
size_type size();
size()函数返回字符串中现在拥有的字符数。
长度(length)
语法:
size_type length();
length()函数返回字符串的长度. 这个数字应该和size()返回的数字相同.
Actually, they have equal results, but semantics is different.
size() act as a method of container, like vector ,set and so forth.
length() represent a property of sequence
.
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯