The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.



Returns a const reference to the largest element at the top of the priority_queue.

const_reference top( ) const;

A reference to the largest element, as determined by the Traits function, object of the priority_queue.

The priority_queue must be nonempty to apply the member function.


// pqueue_top.cpp
// compile with: /EHsc
#include <queue>
#include <iostream>

int main( )
   using namespace std;
   priority_queue<int> q1;

   q1.push( 10 );
   q1.push( 30 );
   q1.push( 20 );

   priority_queue<int>::size_type i;
   i = q1.size( );
   cout << "The priority_queue length is " << i << "." << endl;

   const int& ii = );
   cout << "The element at the top of the priority_queue is "
        << ii << "." << endl;
The priority_queue length is 3.
The element at the top of the priority_queue is 30.


Header: <queue>

Namespace: std