std::vector in C++
From the C++ cheat sheet · Arrays & Vectors · verified Jul 2026
std::vector
The default resizable array.
cpp
// Quick Reference
#include <vector>
std::vector<int> v = {1, 2, 3};
v.push_back(4);
v[0]; v.size();
v.erase(v.begin());💡 std::vector is the go-to container - contiguous storage, cache-friendly, resizable.
⚡ reserve(n) up front avoids repeated reallocations when you know the size.
📌 operator[] is unchecked; .at() throws std::out_of_range on a bad index.
🟢 emplace_back constructs the element in place; push_back copies/moves an existing one.
vectorcontainers