C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C++ Vector clear()This function removes all the elements from the vector. SyntaxConsider a vector v. Syntax would be: v.clear(); ParameterIt does not contain any parameter. Return valueIt does not return any value. ExampleLet's see a simple 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: Elements of v vector are :1 2 3 4 5 In this example, clear() function removes all the elements from the vector.
Next TopicC++ Vector
|