Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- //////// vector size vs. vector capacity
- //////// Size: the number of items currently in the vector
- //////// Capacity: how many items can be fit in the vector before it is "full". Once full, adding new items will result in a new, larger block of memory being allocated and the existing items being copied to it
- //////// source: https://stackoverflow.com/a/6296965/9868445
- int main(){
- vector <int> a;
- a.push_back(1);
- a.push_back(2);
- a.push_back(3);
- cout << a.size() << endl;
- cout << a.capacity() << endl;
- a.pop_back();
- a.pop_back();
- a.pop_back();
- cout << a.size() << endl;
- cout << a.capacity() << endl;
- a.push_back(1);
- a.push_back(2);
- a.push_back(3);
- a.push_back(4);
- cout << a.size() << endl;
- cout << a.capacity() << endl;
- a.push_back(5);
- cout << a.size() << endl;
- cout << a.capacity() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement