English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This function removes all elements from the vector.
Vector (vector) v. Syntax is:
v.clear();
It does not contain any parameters.
It does not return any value.
Remove all elements from the vector.
#include<iostream> #include<vector> using namespace std; int main() { vector<int> v{1,2,3,4,5}; cout << "The elements of vector v are:\t"; for(int i = 0; i < v.size(); i++) cout << v[i] << " \t"; v.clear(); for(int i = 0; i < v.size(); i++) cout << v[i]; return 0; }
Output Result:
The elements of vector v are:1 2 3 4 5
In this example, the clear() function removes all elements from the vector (vector).