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

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

      2. 迭代器的默认值是什么?

        What is an iterator#39;s default value?(迭代器的默认值是什么?)
        • <bdo id='sRlqQ'></bdo><ul id='sRlqQ'></ul>
            <legend id='sRlqQ'><style id='sRlqQ'><dir id='sRlqQ'><q id='sRlqQ'></q></dir></style></legend>
          1. <i id='sRlqQ'><tr id='sRlqQ'><dt id='sRlqQ'><q id='sRlqQ'><span id='sRlqQ'><b id='sRlqQ'><form id='sRlqQ'><ins id='sRlqQ'></ins><ul id='sRlqQ'></ul><sub id='sRlqQ'></sub></form><legend id='sRlqQ'></legend><bdo id='sRlqQ'><pre id='sRlqQ'><center id='sRlqQ'></center></pre></bdo></b><th id='sRlqQ'></th></span></q></dt></tr></i><div id='sRlqQ'><tfoot id='sRlqQ'></tfoot><dl id='sRlqQ'><fieldset id='sRlqQ'></fieldset></dl></div>

                  <tfoot id='sRlqQ'></tfoot>
                    <tbody id='sRlqQ'></tbody>

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

                  本文介绍了迭代器的默认值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  对于我使用的任何 STL 容器,如果我使用迭代器的默认构造函数声明一个迭代器(该特定容器类型的),迭代器将被初始化为什么?

                  For any STL container that I'm using, if I declare an iterator (of this particular container type) using the iterator's default constructor, what will the iterator be initialised to?

                  例如,我有:

                  std::list<void*> address_list;
                  std::list<void*>::iterator iter;
                  

                  iter 将被初始化为什么?

                  What will iter be initialised to?

                  推荐答案

                  约定为容器的NULL迭代器",用于表示无结果,比较等于container.end().

                  By convention a "NULL iterator" for containers, which is used to indicate no result, compares equal to the result of container.end().

                   std::vector<X>::iterator iter = std::find(my_vec.begin(), my_vec.end(), x);
                   if (iter == my_vec.end()) {
                       //no result found; iter points to "nothing"
                   }
                  

                  然而,由于默认构造的容器迭代器不与任何特定容器相关联,因此它没有任何价值.因此,它只是一个未初始化的变量,唯一合法的操作是为其分配一个有效的迭代器.

                  However, since a default-constructed container iterator is not associated with any particular container, there is no good value it could take. Therefore it is just an uninitialized variable and the only legal operation to do with it is to assign a valid iterator to it.

                   std::vector<X>::iterator iter;  //no particular value
                   iter = some_vector.begin();  //iter is now usable
                  

                  <小时>

                  对于其他类型的迭代器,这可能不是真的.例如,在 istream_iterator 的情况下,默认构造的迭代器表示(比较等于)一个 istream_iterator 已经达到输入流的 EOF.


                  For other kinds of iterators this might not be true. E.g in case of istream_iterator, a default-constructed iterator represents (compares equal to) an istream_iterator which has reached the EOF of an input stream.

                  这篇关于迭代器的默认值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is the past-the-end iterator in STL C++?(STL C++ 中的最后迭代器是什么?)
                  vector::at vs. vector::operator[](vector::at 与 vector::operator[])
                  C++ equivalent of StringBuffer/StringBuilder?(C++ 等效于 StringBuffer/StringBuilder?)
                  Adding types to the std namespace(将类型添加到 std 命名空间)
                  Is the C++ std::set thread-safe?(C++ std::set 线程安全吗?)
                  How to use std::find/std::find_if with a vector of custom class objects?(如何将 std::find/std::find_if 与自定义类对象的向量一起使用?)
                1. <small id='8vkqT'></small><noframes id='8vkqT'>

                    <tfoot id='8vkqT'></tfoot>
                        <bdo id='8vkqT'></bdo><ul id='8vkqT'></ul>
                          <tbody id='8vkqT'></tbody>
                      • <legend id='8vkqT'><style id='8vkqT'><dir id='8vkqT'><q id='8vkqT'></q></dir></style></legend>
                        <i id='8vkqT'><tr id='8vkqT'><dt id='8vkqT'><q id='8vkqT'><span id='8vkqT'><b id='8vkqT'><form id='8vkqT'><ins id='8vkqT'></ins><ul id='8vkqT'></ul><sub id='8vkqT'></sub></form><legend id='8vkqT'></legend><bdo id='8vkqT'><pre id='8vkqT'><center id='8vkqT'></center></pre></bdo></b><th id='8vkqT'></th></span></q></dt></tr></i><div id='8vkqT'><tfoot id='8vkqT'></tfoot><dl id='8vkqT'><fieldset id='8vkqT'></fieldset></dl></div>