CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <vector>
using namespace std;
void* operator new(size_t s)
{
cout << "allocated " << s << endl;
void* ptr = malloc(s);
return ptr;
}
int main()
{
vector<int> v{1,2,3,4,5,6,7,8,9};
cout << "Capacity : " << v.capacity() << " and size: " << v.size() << endl;
v.erase(v.begin(),v.begin()+4);
cout << "Capacity : " << v.capacity() << " and size: " << v.size() << endl;
v.shrink_to_fit();
cout << "Capacity : " << v.capacity() << " and size: " << v.size() << endl;
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run