list::front

傳回第一個項目的參考加入至清單。

reference front( ); 
const_reference front( ) const;

傳回值

如果清單是空的,則傳回未定義。

備註

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

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

範例

// 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 Class

list::back 和 list::front

標準樣板程式庫