c++ - 迭代是否遍历整个列表

标签 c++ iteration stdlist

拿这段代码:

std::list<int> intList;
for (int i = 0; i < 10; ++i) {
    intList.push_back( 1 << i );
}

std::list<int>::const_iterator iterator;
for (iterator = intList.begin(); iterator != intList.end(); ++iterator) {
    std::cout << *iterator;
}

我看到了如何遍历列表。查看迭代,我认为您跳过了最后一项。是这种情况吗?如果是,最好的解决方法是什么。

最佳答案

实际上,并没有跳过最后一项。指向 intList.end()-1 的迭代器指向最后一项,而不是您可能认为的 intList.end()

关于c++ - 迭代是否遍历整个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45195173/

相关文章:

python - 如何在不迭代的情况下读取行

c++ - 如何在结构体的 `std::list`处进行搜索?

c++ - spdlog:无法刷新/写入文件

c++ - 静态符号弱或强

c++ - 为什么启动项目不执行依赖项目

c++ - 如何对多维数组进行排序?

python - 使用迭代和集合重写列表(根据条件删除条目)

c - 跳过/忽略包含 c 中值的数组索引

c++ - 通过引用从 std::list 中移除元素

c++ - std::list 是一个循环列表!!等等,什么?