添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
有腹肌的啄木鸟  ·  使用 JdbcTemplate ...·  2 周前    · 
爱跑步的钥匙  ·  MybatisPlus学习笔记 | ...·  2 周前    · 
咆哮的馒头  ·  Get Nth Entry from ...·  2 周前    · 
留胡子的汤圆  ·  SharePoint 搜索 REST ...·  1 周前    · 
没有腹肌的开水瓶  ·  Exception in thread ...·  1 周前    · 
拉风的眼镜  ·  WebExceptionHandler ...·  1 年前    · 
开朗的啄木鸟  ·  javax.swing.text.html. ...·  1 年前    · 

std::string::size

Return length of string

Returns the length of the string, in terms of bytes.
This is the number of actual bytes that conform the contents of the string , which is not necessarily equal to its storage capacity .
Note that string objects handle bytes without knowledge of the encoding that may eventually be used to encode the characters it contains. Therefore, the value returned may not correspond to the actual number of encoded characters in sequences of multi-byte or variable-length characters (such as UTF-8).
Both string::size and string::length are synonyms and return the same value.

std::string::length

Return length of string

Returns the length of the string, in terms of bytes.
This is the number of actual bytes that conform the contents of the string , which is not necessarily equal to its storage capacity .
Note that string objects handle bytes without knowledge of the encoding that may eventually be used to encode the characters it contains. Therefore, the value returned may not correspond to the actual number of encoded characters in sequences of multi-byte or variable-length characters (such as UTF-8).
Both string::size and string::length are synonyms and return the exact same value.

所以两者的微小区别就是:

size() 一般用作返回容器大小的方法

length() 一般用作返回一个序列的长度

❤ 点击这里 -> 订阅《PAT | 蓝桥 | LeetCode学习路径 & 刷题经验》by 柳婼

❤ 点击这里 -> 订阅《从放弃C语言到使用C++刷算法的简明教程》by 柳婼

❤ 点击这里 -> 订阅PAT甲级乙级、蓝桥杯、GPLT天梯赛、LeetCode题解离线版

发布于 分类 Code 标签