C++ Vector clear
This function eliminates all elements from the vector.
Syntax
Consider a vector v. Syntax would be:
Example
v.clear();
Parameter
It does not contain any parameter.
Return value
It does not return any value.
Example
Let's see a simple example.
Example
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> v{1,2,3,4,5};
cout<<"Elements of v vector are :";
for(int i=0;i<v.size();i++)
cout<<v[i]<<" ";
v.clear();
for(int i=0;i<v.size();i++)
cout<<v[i];
return 0;
}
Output:
Output
Elements of v vector are :1 2 3 4 5
In this instance, the clear method eliminates all elements within the vector.