Skip to content
Justice Tech School

std::vector

vector is a resizable array. push_back, pop_back, size, at, insert and erase.

Example
#include <iostream>
#include <vector>

int main() {
  std::vector<int> v = {1, 2, 3};
  v.push_back(4);
  v.insert(v.begin(), 0);
  v.erase(v.begin() + 1);
  for (int x : v) std::cout << x << " ";
  std::cout << v.size() << "\n";
  return 0;
}

Result

0 2 3 4 4

Exercise

Add to the end.

v.(5)

Quiz Test

What does size() return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.