cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : queue : front
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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::front public member function
      value_type& front ( );
const value_type& front ( ) const;

Access next element

Returns a reference to the next element in the queue. This is the "oldest" element in the queue and the same element that is popped out from the queue if member queue::pop is called.

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

Parameters

none

Return value

A reference to the next 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

// queue::front
#include <iostream>
#include <queue>
using namespace std;

int main ()
{
  queue<int> myqueue;

  myqueue.push(77);
  myqueue.push(16);

  myqueue.front() -= myqueue.back();

  cout << "myqueue.front() is now " << myqueue.front() << endl;

  return 0;
}

Output:

myqueue.front() is now 61

Complexity

Constant.

See also

queue::pop Delete next element (public member function)
queue::back Access last element (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us