1#include <vector>
2
3int main() {
4 std::vector<int> myVector = { 666, 1337, 420 };
5
6 size_t size = myVector.size(); // 3
7
8 myVector.push_back(399); // Add 399 to the end of the vector
9
10 size = myVector.size(); // 4
11}
1#include <iostream>
2#include <vector>
3
4using namespace std;
5
6int main(void) {
7 vector<int> v;
8
9 cout << "Initial vector size = " << v.size() << endl;
10
11 v.resize(5, 10);
12 cout << "Vector size after resize = " << v.size() << endl;
13
14 cout << "Vector contains following elements" << endl;
15 for (int i = 0; i < v.size(); ++i)
16 cout << v[i] << endl;
17
18 return 0;
19}
1// create a vector with 20 integer elements
2std::vector<int> arr(20);
3
4for(int x = 0; x < 20; ++x)
5 arr[x] = x;
1#include <vector>
2
3auto n = 20
4// create a vector with n=20 integer elements
5std::vector<int> arr(n);