Click here to Skip to main content
15,886,720 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
HI
may someone explain what is the iterator in c++ ? and when it uses and why?

Thanks
Posted

A Brief description about Iterator...
http://www.cplusplus.com/reference/iterator/[^]
 
Share this answer
 
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
C++
std::class_name<template_parameters>::iterator name


Take a look at this tutorial as well: http://www.cprogramming.com/tutorial/stl/iterators.html[^]
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900