multimap::begin
傳回定址Iterator指向multimap的第一個項目。
const_iterator begin( ) const;
iterator begin( );
傳回值
解決一的雙向Iterator順利空白multimap、multimap的第一個項目或位置。
註解
如果 begin 的傳回值指派給 const_iterator,無法修改multimap物件的項目。 如果 begin 的傳回值指派給 iterator,可以修改在multimap物件的項目。
範例
// multimap_begin.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
multimap <int, int> m1;
multimap <int, int> :: iterator m1_Iter;
multimap <int, int> :: const_iterator m1_cIter;
typedef pair <int, int> Int_Pair;
m1.insert ( Int_Pair ( 0, 0 ) );
m1.insert ( Int_Pair ( 1, 1 ) );
m1.insert ( Int_Pair ( 2, 4 ) );
m1_cIter = m1.begin ( );
cout << "The first element of m1 is " << m1_cIter -> first << endl;
m1_Iter = m1.begin ( );
m1.erase ( m1_Iter );
// The following 2 lines would err as the iterator is const
// m1_cIter = m1.begin ( );
// m1.erase ( m1_cIter );
m1_cIter = m1.begin( );
cout << "First element of m1 is now " << m1_cIter -> first << endl;
}
需求
標題: <map>
命名空間: std