queue::back
キューの戻るの最後の参照や最近追加された要素を返します。
reference back( );
const_reference back( ) const;
戻り値
キュー内の最後の要素。 キューが空の場合、戻り値は未定義です。
解説
戻る の戻り値が const_referenceに割り当てると、キュー オブジェクトは変更できません。 戻る の戻り値が リファレンスに割り当てると、キュー オブジェクトを変更できます。
_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;
}
出力
The integer at the back of queue q1 is 11.
The integer at the front of queue q1 is 10.
必要条件
ヘッダー: <キュー>
名前空間: std