什么是c ++中的迭代器? [英] What is the iterator in c++?

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

问题描述

HI


有人可以解释一下c ++中的迭代器是什么?什么时候使用?为什么?



谢谢

HI
may someone explain what is the iterator in c++ ? and when it uses and why?

Thanks

推荐答案

关于迭代器的简要介绍...

http://www.cplusplus.com/reference/iterator/ [ ^ ]
A Brief description about Iterator...
http://www.cplusplus.com/reference/iterator/[^]


概念迭代器是理解C ++标准模板库(STL)的基础,因为迭代器提供了一种访问存储在容器类中的数据的方法,例如向量,映射,列表等。



您可以将迭代器视为指向属于较大容器容器的项目。例如,所有容器都支持一个名为begin的函数,它将返回一个指向容器开头的迭代器(第一个元素)和函数end,它返回一个对应于已经到达容器末尾的迭代器。实际上,您可以通过使用*取消引用迭代器来访问元素,就像取消引用指针一样。



请求适合特定的迭代器STL模板类,你使用语法

The concept of an iterator is fundamental to understanding the C++ Standard Template Library (STL) because iterators provide a means for accessing data stored in container classes such a vector, map, list, etc.

You can think of an iterator as pointing to an item that is part of a larger container of items. For instance, all containers support a function called begin, which will return an iterator pointing to the beginning of the container (the first element) and function, end, that returns an iterator corresponding to having reached the end of the container. In fact, you can access the element by "dereferencing" the iterator with a *, just as you would dereference a pointer.

To request an iterator appropriate for a particular STL templated class, you use the syntax
std::class_name<template_parameters>::iterator name





请看一下本教程: http://www.cprogramming.com /tutorial/stl/iterators.html [ ^ ]


不是通过在这里发布问题来尝试学习语言,而是花时间阅读文档 [ ^ ]或获取一本书。
Rather than trying to learn the language by posting questions here, your time would be better spent reading the documentation[^] or getting hold of a book.


这篇关于什么是c ++中的迭代器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆