Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Erases the elements of the vector.
void clear( );
Example
// vector_clear.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
using namespace std;
int main( )
{
vector <int> vec;
vec.push_back(10);
vec.push_back(20);
vec.push_back(30);
cout << "The size of vec is " << vec.size() << endl;
cout << "The capacity of vec is " << vec.capacity() << endl;
vec.clear();
cout << "The size of vec after clearing is " << vec.size() << endl;
cout << "The capacity of vec after clearing is " << vec.capacity() << endl;}
The size of vec is 3 The capacity of vec is 3 The size of vec after clearing is 0 The capacity of vec after clearing is 3
Requirements
Header: <vector>
Namespace: std