Jump to content

C++ Language/Std/Stl/Iterators/BasicIterators

From Wikibooks, open books for an open world

An iterator is an object that reprsents a position within some collection class:
void OutputVector(std::vector<int>& x) {
  std::vector<int>::iterator piIter;
  for (piIter = x.begin(); piIter != x.end(); ++piIter) {
    int iVar = *piIter;
    std::cout << iVar;
  }
}

Additional information about basic iterators (includes interactive examples)