back [C++ Reference]
Keywords: stl,vector,back
Date: 2009-12-01T05:17:00-0800

[[back]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## back

Syntax:

        #include <vector>
        TYPE& back();
        const TYPE& back() const;

The back() function returns a reference to the last element in the vector. For example:

       vector<int> v;
       for( int i = 0; i < 5; i++ ) {
         v.push_back(i);
       }
       cout << "The first element is " << v.front()
            << " and the last element is " << v.back() << endl;

This code produces the following output:

       The first element is 0 and the last element is 4

The back() function runs in constant time.

Related Topics: front, pop_back

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •