Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Iterators are objects that point to elements in a container. They provide a uniform way to traverse different STL containers (vector, list, set, etc.).
Iterators behave just like pointers. You can increment them (it++) and dereference them (*it).
vector<int> v = {10, 20, 30};
vector<int>::iterator it = v.begin();
cout << *it; // 10
it++; // Points to 20
cout << *it; // 20Returns an iterator pointing to the FIRST element.
Returns an iterator pointing to the position AFTER the last element.
Iterators often have complex type names. In modern C++, always use auto to simplify your loops.
for (auto it = v.begin(); it != v.end(); it++) { ... }