Open In App

Vector in C++ STL

Last Updated : 15 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

C++ vector is a dynamic array that stores collection of elements same type in contiguous memory. It has the ability to resize itself automatically when an element is inserted or deleted.

Create a Vector

Before creating a vector, we must know that a vector is defined as the std::vector class template in the <vector> header file.

C++
vector<T> v;

where T is the type of elements and v is the name assigned to the vector.

Now we are creating an instance of std::vector class. This requires us to provide the type of elements as template parameter.