0Pricing
C++ Academy · Lesson

std::vector Basics: push_back size capacity

Create, grow and inspect vectors and understand the capacity vs size distinction.

Why std::vector?

std::vector is the default container in C++. It grows automatically, manages memory for you, and gives O(1) random access. Use it unless you have a specific reason not to.

Including and Declaring

Include <vector> and declare with the element type as a template parameter.

#include <vector>

std::vector<int> nums;
std::vector<std::string> names = {"Ada", "Bob"};

All lessons in this course

  1. std::vector Basics: push_back size capacity
  2. Iterating Vectors: index range-for iterators
  3. Modifying Vectors: insert erase clear
  4. Vector vs std::array vs C Array
← Back to C++ Academy