STL中的string
类有两个方法size()
和length()
用来返回字符串的长度。
两者在实现上没有区别:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
> 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; } |
评论