1. <tfoot id='BApev'></tfoot>
      <i id='BApev'><tr id='BApev'><dt id='BApev'><q id='BApev'><span id='BApev'><b id='BApev'><form id='BApev'><ins id='BApev'></ins><ul id='BApev'></ul><sub id='BApev'></sub></form><legend id='BApev'></legend><bdo id='BApev'><pre id='BApev'><center id='BApev'></center></pre></bdo></b><th id='BApev'></th></span></q></dt></tr></i><div id='BApev'><tfoot id='BApev'></tfoot><dl id='BApev'><fieldset id='BApev'></fieldset></dl></div>
      • <bdo id='BApev'></bdo><ul id='BApev'></ul>

      <small id='BApev'></small><noframes id='BApev'>

    2. <legend id='BApev'><style id='BApev'><dir id='BApev'><q id='BApev'></q></dir></style></legend>

      std::string length() 和 size() 成员函数

      时间:2024-05-12

        1. <small id='3Hq5A'></small><noframes id='3Hq5A'>

            <bdo id='3Hq5A'></bdo><ul id='3Hq5A'></ul>
            <i id='3Hq5A'><tr id='3Hq5A'><dt id='3Hq5A'><q id='3Hq5A'><span id='3Hq5A'><b id='3Hq5A'><form id='3Hq5A'><ins id='3Hq5A'></ins><ul id='3Hq5A'></ul><sub id='3Hq5A'></sub></form><legend id='3Hq5A'></legend><bdo id='3Hq5A'><pre id='3Hq5A'><center id='3Hq5A'></center></pre></bdo></b><th id='3Hq5A'></th></span></q></dt></tr></i><div id='3Hq5A'><tfoot id='3Hq5A'></tfoot><dl id='3Hq5A'><fieldset id='3Hq5A'></fieldset></dl></div>
              <tbody id='3Hq5A'></tbody>

            <legend id='3Hq5A'><style id='3Hq5A'><dir id='3Hq5A'><q id='3Hq5A'></q></dir></style></legend>

                <tfoot id='3Hq5A'></tfoot>
                本文介绍了std::string length() 和 size() 成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在阅读这个问题的答案,发现实际上有一个方法叫做length() 用于 std::string(我一直使用 size()).在 std::string 类中使用此方法是否有任何特定原因?我阅读了 MSDN 和 CppRefernce,它们似乎表明 size()length() 之间没有区别.如果是这样,是不是让课程的用户更加困惑?

                I was reading the answers for this question and found that there is actually a method called length() for std::string (I always used size()). Is there any specific reason for having this method in std::string class? I read both MSDN and CppRefernce, and they seem to indicate that there is no difference between size() and length(). If that is so, isn't it making more confusing for the user of the class?

                推荐答案

                根据 文档,这些只是同义词.size() 是否与其他 STL 容器(如vectormap)保持一致,并且length() 是要符合大多数人对字符串的直观概念.人们通常谈论一个单词、句子或段落的长度,而不是它的大小,所以 length() 是为了让事情更具可读性.

                As per the documentation, these are just synonyms. size() is there to be consistent with other STL containers (like vector, map, etc.) and length() is to be consistent with most peoples' intuitive notion of character strings. People usually talk about a word, sentence or paragraph's length, not its size, so length() is there to make things more readable.

                这篇关于std::string length() 和 size() 成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:迭代器的默认值是什么? 下一篇:插入地图的首选/惯用方法是什么?

                相关文章

              1. <i id='1VloU'><tr id='1VloU'><dt id='1VloU'><q id='1VloU'><span id='1VloU'><b id='1VloU'><form id='1VloU'><ins id='1VloU'></ins><ul id='1VloU'></ul><sub id='1VloU'></sub></form><legend id='1VloU'></legend><bdo id='1VloU'><pre id='1VloU'><center id='1VloU'></center></pre></bdo></b><th id='1VloU'></th></span></q></dt></tr></i><div id='1VloU'><tfoot id='1VloU'></tfoot><dl id='1VloU'><fieldset id='1VloU'></fieldset></dl></div>

                <legend id='1VloU'><style id='1VloU'><dir id='1VloU'><q id='1VloU'></q></dir></style></legend>

              2. <tfoot id='1VloU'></tfoot>

                <small id='1VloU'></small><noframes id='1VloU'>

                      <bdo id='1VloU'></bdo><ul id='1VloU'></ul>