STL中的string
类有两个方法size()
和length()
用来返回字符串的长度。 两者在实现上没有区别:
> sed -n 907,918p /usr/include/c++/7/bits/basic_string.h
// Capacity:
/// Returns the number of characters in the string, not including any
/// null-termination.
size_type
size() const _GLIBCXX_NOEXCEPT
{ return _M_string_length; }
/// Returns the number of characters in the string, not including any
/// null-termination.
size_type
length() const _GLIBCXX_NOEXCEPT
{ return _M_string_length; }
此处评论已关闭