Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
queue
comparison operators
queue::queue
member functions:
queue::back
queue::empty
queue::front
queue::pop
queue::push
queue::size


queue::back

public member function
      value_type& back ( );
const value_type& back ( ) const;

Access last element

Returns a reference to the last element in the queue. This is the "newest" element in the queue i.e. the last element pushed into queue.

This member function effectively calls the member with the same name in the underlying container object.

Parameters

none

Return value

A reference to the last element in the queue.

Member type value_type is defined to the type of value contained by the underlying container, which shall be the same as the first template parameter (T).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// queue::front
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
  queue<int> myqueue;
  myqueue.push(12);
  myqueue.push(75);   // this is now the back
  myqueue.back() -= myqueue.front();
  cout << "myqueue.back() is now " << myqueue.back() << endl;
  return 0;
}


Output:
myqueue.back() is now 63

Complexity

Constant.

See also