#include <iostream> #include <vector> int main() { using std::cout; using std::vector; // Create a vector with values 1 .. 10 vector<int> v(10); std::cout << "v has size " << v.size() << " and capacity " << v.capacity() << "\n"; // Now add 90 values, and print the size and capacity after each insert for(int i = 11; i <= 100; ++i) { v.push_back(i); std::cout << "v has size " << v.size() << " and capacity " << v.capacity() << ". Memory range: " << &v.front() << " -- " << &v.back() << "\n"; } return 0; }
Standard input is empty
v has size 10 and capacity 10 v has size 11 and capacity 20. Memory range: 0x9b4fa40 -- 0x9b4fa68 v has size 12 and capacity 20. Memory range: 0x9b4fa40 -- 0x9b4fa6c v has size 13 and capacity 20. Memory range: 0x9b4fa40 -- 0x9b4fa70 v has size 14 and capacity 20. Memory range: 0x9b4fa40 -- 0x9b4fa74 v has size 15 and capacity 20. Memory range: 0x9b4fa40 -- 0x9b4fa78 v has size 16 and capacity 20. Memory range: 0x9b4fa40 -- 0x9b4fa7c v has size 17 and capacity 20. Memory range: 0x9b4fa40 -- 0x9b4fa80 v has size 18 and capacity 20. Memory range: 0x9b4fa40 -- 0x9b4fa84 v has size 19 and capacity 20. Memory range: 0x9b4fa40 -- 0x9b4fa88 v has size 20 and capacity 20. Memory range: 0x9b4fa40 -- 0x9b4fa8c v has size 21 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fae8 v has size 22 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4faec v has size 23 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4faf0 v has size 24 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4faf4 v has size 25 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4faf8 v has size 26 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fafc v has size 27 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb00 v has size 28 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb04 v has size 29 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb08 v has size 30 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb0c v has size 31 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb10 v has size 32 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb14 v has size 33 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb18 v has size 34 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb1c v has size 35 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb20 v has size 36 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb24 v has size 37 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb28 v has size 38 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb2c v has size 39 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb30 v has size 40 and capacity 40. Memory range: 0x9b4fa98 -- 0x9b4fb34 v has size 41 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fbe0 v has size 42 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fbe4 v has size 43 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fbe8 v has size 44 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fbec v has size 45 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fbf0 v has size 46 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fbf4 v has size 47 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fbf8 v has size 48 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fbfc v has size 49 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc00 v has size 50 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc04 v has size 51 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc08 v has size 52 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc0c v has size 53 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc10 v has size 54 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc14 v has size 55 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc18 v has size 56 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc1c v has size 57 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc20 v has size 58 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc24 v has size 59 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc28 v has size 60 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc2c v has size 61 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc30 v has size 62 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc34 v has size 63 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc38 v has size 64 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc3c v has size 65 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc40 v has size 66 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc44 v has size 67 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc48 v has size 68 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc4c v has size 69 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc50 v has size 70 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc54 v has size 71 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc58 v has size 72 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc5c v has size 73 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc60 v has size 74 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc64 v has size 75 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc68 v has size 76 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc6c v has size 77 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc70 v has size 78 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc74 v has size 79 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc78 v has size 80 and capacity 80. Memory range: 0x9b4fb40 -- 0x9b4fc7c v has size 81 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fdc8 v has size 82 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fdcc v has size 83 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fdd0 v has size 84 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fdd4 v has size 85 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fdd8 v has size 86 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fddc v has size 87 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fde0 v has size 88 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fde4 v has size 89 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fde8 v has size 90 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fdec v has size 91 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fdf0 v has size 92 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fdf4 v has size 93 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fdf8 v has size 94 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fdfc v has size 95 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fe00 v has size 96 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fe04 v has size 97 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fe08 v has size 98 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fe0c v has size 99 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fe10 v has size 100 and capacity 160. Memory range: 0x9b4fc88 -- 0x9b4fe14