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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <iostream> #include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
vector<int> vecnum; vecnum.push_back(1); vecnum.push_back(2); vecnum.push_back(3); vecnum.push_back(4); vecnum.push_back(5); vecnum.push_back(6); vecnum.push_back(7);
cout << "old: size = " << vecnum.size() << " ; capacity = " << vecnum.capacity() << endl;
vecnum.clear(); cout << "clear():" << endl; cout << "last: size = " << vecnum.size() << " ; capacity = " << vecnum.capacity() << endl;
vecnum.push_back(1); vecnum.push_back(2); vecnum.push_back(3); vecnum.push_back(4); vecnum.push_back(5); vecnum.push_back(6); vecnum.push_back(7);
vector<int>().swap(vecnum); cout << "swap:" << endl; cout << "last: size = " << vecnum.size() << " ; capacity = " << vecnum.capacity() << endl;
return 0; }
|