![]() P = &a // Store the address of a in pointer pī = *p // Put the Value of the pointer p in bĬout::const_iterator i = vectorOfObjects.end() Let’s understand through a proper code example. End() - it returns the next to the last element of the container.Begin() - it returns the first element of the container.The container provides the data type to the iterators, and the container class provides two basic functions which help the iterator in iterating through the elements of the container. In general data structures like arrays, we can use the index variable to loop through the container, but in advanced data structures like a tree or unordered data structures where we don’t have the index variable to loop through, we use iterators to traverse it. It provides a very generic approach to traversing through the elements of a container. We use an iterator to iterate the container elements although we can use the conventional loops, iterators have the upper hand on iterating through a container. In C++, an iterator is an object like a pointer, pointing to the elements inside an array, list and any other data structure. Iterators are another powerful mechanism in C++ that helps you iterate over complex data structures like a tree and sets where we don’t have the indices of elements inside, like an array. Why We Can’t Dereference an Iterator in C++. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |