返回解决的迭代器在基于的第一个元素。
const_iterator begin( ) const;
iterator begin( );
返回值
解析一双向的迭代器在成功空基于的基于的第一个元素或位置。
备注
如果 begin 的返回值赋给 const_iterator,不能修改在基于对象的元素。如果 begin 的返回值赋给 iterator,可以修改在基于对象的元素。
示例
// 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