다음을 통해 공유


map::difference_type

반복기가 가리키는 요소 사이의 범위에서 지도 요소 개수를 나타내는 데 사용 되는 부호 있는 정수 형식입니다.

typedef allocator_type::difference_type difference_type;

설명

difference_type 빼기 또는 컨테이너의 반복기를 증가 하면 형식이 반환 됩니다.difference_type 범위의 요소 수를 나타내는 데 일반적으로 사용 [_First, _Last) 반복기 사이의 _First 및 _Last을 가리키는 요소가 포함 _First 및 범위의 요소 수를 포함 하지 않습니다, 요소를 가리키는 _Last.

하지만 이때 difference_type 클래스의 집합 반복기 사이의 빼기만 벡터와 같은 임의 액세스 컨테이너에서 제공 하는 임의 액세스 반복기 지와 같이 해독 가능한 컨테이너에서 지원 되는 양방향 반복기를 포함 하는 입력된 반복기의 요구 사항을 충족 하는 모든 반복기를 사용할 수 있습니다.

예제

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

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

   m1.insert ( Int_Pair ( 2, 20 ) );
   m1.insert ( Int_Pair ( 1, 10 ) );
   m1.insert ( Int_Pair ( 3, 20 ) );
   m1.insert ( Int_Pair ( 2, 30 ) );

   map <int, int>::iterator m1_Iter, m1_bIter, m1_eIter;
   m1_bIter = m1.begin( );
   m1_eIter = m1.end( );

   // Count the number of elements in a map
   map <int, int>::difference_type  df_count = 1;
   m1_Iter = m1.begin( );
   while ( m1_Iter != m1_eIter)
   {
      df_count++;
      m1_Iter++;
   }

   cout << "The number of elements in the map m1 is: " 
        << df_count << "." << endl;
}
  

요구 사항

헤더: <map>

네임 스페이스: std

참고 항목

참조

map Class

표준 템플릿 라이브러리