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; }
最后修改:2018 年 12 月 16 日
喜欢就给我点赞吧