queue::back
以傳回的參考和最新加入的項目在佇列中。
reference back( );
const_reference back( ) const;
傳回值
佇列的最後一個項目。 如果佇列是空的,則傳回值為 undefined。
備註
如果傳回值 back 給 const_reference,無法修改佇列物件。 如果的傳回值指派給 backreference,可以修改佇列物件。
在以 _SECURE_SCL 1 時,執行時會發生錯誤,如果您嘗試存取正在空佇列的項目。如需詳細資訊,請參閱已檢查的迭代器。
範例
// 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.
需求
標題: <佇列>
命名空間: std