次の方法で共有


map::begin

マップの一つ目の要素を指定する反復子を返します。

const_iterator begin( ) const; 
iterator begin( );

戻り値

空のマップを成功するマップの最初の要素または場所を示す双方向の反復子。

コメント

開始 の戻り値が const_iteratorに割り当てられる場合、オブジェクト要素は変更できません。 開始 の戻り値が 反復子に割り当てると、マップ オブジェクトの要素を変更できます。

使用例

// map_begin.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main( )
{
   using namespace std;
   map <int, int> m1;

   map <int, int> :: iterator m1_Iter;
   map <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 because the iterator is const
   // m1_cIter = m1.begin ( );
   // m1.erase ( m1_cIter );

   m1_cIter = m1.begin( );
   cout << "The first element of m1 is now " << m1_cIter -> first << endl;
}
  

必要条件

ヘッダー: <map>

名前空間: std

参照

関連項目

map クラス

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