共用方式為


queue::front

傳回第一個項目的參考佇列的前端。

reference front( );
const_reference front( ) const;

傳回值

佇列的第一個項目。 如果佇列是空的,則傳回值為 undefined。

備註

如果 front 的傳回值指派給 const_reference,無法修改佇列物件。 如果 front 的傳回值指派給 reference,可以修改佇列物件。

成員函式傳回 reference 至受控制序列的第一個項目,此序列必須為非空白序列。

當以 _SECURE_SCL 1 編譯時,執行時會發生錯誤,如果您嘗試存取在空的佇列中的項目。 如需詳細資訊,請參閱檢查過的 Iterator

範例

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

int main() {
   using namespace std;
   queue <int> q1;

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

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

   int& ii = q1.back( );
   int& iii = q1.front( );

   cout << "The integer at the back of queue q1 is " << ii 
        << "." << endl;
   cout << "The integer at the front of queue q1 is " << iii 
        << "." << endl;
}

Output

The queue length is 3.
The integer at the back of queue q1 is 30.
The integer at the front of queue q1 is 10.

需求

標題: <queue>

命名空間: std

請參閱

參考

queue Class

queue Functions

標準樣板程式庫