![]() |
VOOZH | about |
In C++, vector clear() is a built-in method used to remove all elements from a vector, making it empty. In this article, we will learn about the vector clear() method in C++.
Let’s take a look at an example that illustrates the vector clear() method:
Vector is Empty
This article covers the syntax, usage, and common examples of the vector clear() method in C++ STL.
The vector clear() method is defined inside the std::vector class in the <vector> header file.
v.clear();
This function does not take any parameters, nor it returns any value.
The below examples demonstrate the use and behaviour of vector clear() method in practical scenarios.
0
4 4
Explanation: As we can see, the vector clear() method does not affects the capacity of the vector. It means that although it deletes the memory