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// stack::top
2#include <iostream> // std::cout
3#include <stack> // std::stack
4
5int main ()
6{
7 std::stack<int> mystack;
8
9 mystack.push(10);
10 mystack.push(20);
11 // .top() gets the last/top element of stack c++
12 mystack.top() -= 5;
13
14 std::cout << "mystack.top() is now " << mystack.top() << '\n';
15
16 return 0;
17}