共用方式為


queue::back

傳回在最後的參考和最近加入的項目在佇列中的上一頁。

reference back( );
const_reference back( ) const;

傳回值

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

備註

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

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

範例

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

int main( ) 
{
   using namespace std;
   queue <int> q1;
   
   q1.push( 10 );
   q1.push( 11 );

   int& i = q1.back( );
   const int& ii = q1.front( );

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

Output

The integer at the back of queue q1 is 11.
The integer at the front of queue q1 is 10.

需求

標題: <queue>

命名空間: std

請參閱

參考

queue Class

queue Functions

標準樣板程式庫