clear(): It is a build-in function in the STL library of C++. This function erases all the elements from the vector. If elements are pointers then the pointer- to memory is not touched in any way.
Synatx:
vecName.clear()
File: stl_vector.h
For Example:
vec = {1,2,3,4,5}
vec.clear() => vec={}
So size of vector is 0.
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){vector<int> vec = {1, 2, 3, 4, 5};vec.clear();cout << vec.size() << "\n";return 0;}
No comments:
Post a Comment