vector<T>

A dynamic array from the STL that automatically manages its size. Provides random access and amortized O(1) push_back.

Syntax

cpp
std::vector<T> v;
v.push_back(value);
v[index];

Example

cpp
#include <vector>

vector<int> nums = {1, 2, 3};
nums.push_back(4);
for (int n : nums) cout << n << " ";
cout << nums.size();     // 4
nums.erase(nums.begin()); // remove first