1vector<int> v;
2cout << v[v.size() - 1];
3cout << *(v.end() - 1);
4cout << *v.rbegin();
5// all three of them work
1// vector::back
2#include <iostream>
3#include <vector>
4
5int main ()
6{
7 std::vector<int> myvector;
8
9 myvector.push_back(10);
10
11 while (myvector.back() != 0)
12 {
13 myvector.push_back ( myvector.back() -1 );
14 }
15
16 std::cout << "myvector contains:";
17 for (unsigned i=0; i<myvector.size() ; i++)
18 std::cout << ' ' << myvector[i];
19 std::cout << '\n';
20
21 return 0;
22}