list::begin
傳回處理的列舉值清單中的第一個項目。
const_iterator begin( ) const;
iterator begin( );
傳回值
解決雙向Iterator的第一個項目清單或是成功空白清單的位置。
備註
如果 begin 的傳回值指派給 const_iterator,無法修改清單中物件的項目。 如果 begin 的傳回值指派給 iterator,可以修改清單中物件的項目。
範例
// list_begin.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
int main( )
{
using namespace std;
list <int> c1;
list <int>::iterator c1_Iter;
list <int>::const_iterator c1_cIter;
c1.push_back( 1 );
c1.push_back( 2 );
c1_Iter = c1.begin( );
cout << "The first element of c1 is " << *c1_Iter << endl;
*c1_Iter = 20;
c1_Iter = c1.begin( );
cout << "The first element of c1 is now " << *c1_Iter << endl;
// The following line would be an error because iterator is const
// *c1_cIter = 200;
}
需求
標題: <list>
命名空間: std