1vector<int> vec;
2vec.push_back(0);
3vec.push_back(1);
4int last_element = vec.back();
5int also_last_element = vec[vec.size() - 1];
6
1#include <iostream>
2#include <vector>
3
4int main()
5{
6 std::vector<int> myvector;
7
8 //add 2 to the back
9 myvector.push_back(2);
10
11 std::cout << myvector.back() << std::endl; //this will print 2
12
13 myvector.push_back(46);
14 std::cout << myvector.back() << std::endl; //prints 46
15
16 return 0;
17
18}
19
20/*Output
212
2246
23*/