Home >>C++ Standard Template Library Tutorial(STL) >C++ Iterators
An object (like a pointer) that generally point towards an element that is inside the container is known as Iterators in C++. The iterators can generally be used to move through the contents of the container. We can say that the iterators are like a pointer that is pointing towards some location and the content can be accessed at that particular location just by using them.
A critical role is played by the Iterators in connecting the algorithm with containers inclusding00 the manipulation of data that has been stored inside the containers. Pointer is the most obvious form of an iterator. A pointer can generally iterate through the elements in an array by using the increment operator (++) as pointer is known to point to the elements in an array. Please note that all the iterators don’t have similar functionality as pointers.
Judging upon the functionality of the iterators, they are generally classified into five major categories that are explained in brief here for your understanding:
These types of iterators are known as the weakest of all the iterators as they have a very limited functionality. This type of iterator are known to be used only once in a single-pass algorithm, in simple words these are the algorithms that generally process the container in a sequential order so that none of the element is allowed to be accessed more than once.
This type of iterators are very similar to the input iterators as they are also known to have a very limited functionality and just like input iterators their only use is in a single-pass algorithm, instead of accessing elements they are used for being assigned elements.
These types of iterators are generally higher in the table of hierarchy as compared to the input and output iterators. They generally consist of all the features that are present in these two iterators. You can get an idea about their functionality through their name as they can generally move in forward direction with a limitation of taking one step at a particular time.
These types of iterators are known to consist every features of forward iterators. But they are very useful as compared to the forward iterator as this iterator is known to overcome the drawback of forward iterators. This is because they have the ability to move in both the directions and they are named bidirectional.
These types of iterators are known to be the most powerful iterators among all. They generally don’t have any limitations like moving sequentially. You can get an idea through their name that they are allowed to access any element randomly that is inside the container. These iterators are the only one that has the same fun functionality as the pointers.
There are generally very few that can prove that iterators are extremely useful to the programmers and encourage them to use it very profoundly. Here are some of the benefits of using the iterators depicted below: