Search⌘ K

What Is a Vector?

Explore the fundamentals of vectors in C++, a dynamic array structure from the STL. Understand how to declare, initialize, and modify vectors, access their elements, and utilize 2D vectors for handling matrix-like data.

Introduction to vectors

In C++, a vector is a dynamic array that can resize itself automatically when elements are added or removed. Vectors are part of the Standard Template Library (STL) and offer a convenient way to work with collections of data.

Including the vector library

To use vectors in your C++ program, include the <vector> header file:

C++
#include <vector>
...