Share via


list::front

リスト内の最初の要素への参照を返します。

reference front( );  const_reference front( ) const;

戻り値

リストが空の場合、戻り値は定義されません。

解説

front の戻り値が const_reference に割り当てられている場合、リスト オブジェクトを変更することはできません。 front の戻り値が reference に割り当てられている場合、リスト オブジェクトを変更できます。

_SECURE_SCL 1 でのコンパイル時に、空のリスト内の要素にアクセスしようとすると、ランタイム エラーが発生します。 詳細については、「チェックを行う反復子」を参照してください。

使用例

// list_front.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main() {
   using namespace std;
   list <int> c1;

   c1.push_back( 10 );

   int& i = c1.front();
   const int& ii = c1.front();

   cout << "The first integer of c1 is " << i << endl;
   i++;
   cout << "The first integer of c1 is " << ii << endl;
}
  

必要条件

ヘッダー: <list>

名前空間: std

参照

関連項目

list クラス

list::back と list::front

標準テンプレート ライブラリ