Vectors and Iterators

std::vector is a dynamic array from the STL. Iterators are used to traverse containers.

#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> v = {1, 2, 3};
  v.push_back(4);

  for (vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
    cout << *it << " ";
  }
}

Vectors grow dynamically and support random access.

← PrevNext →