multimap::value_type
맵의 요소에 저장 된 개체의 형식을 나타내는 형식.
typedef pair<const Key, Type> value_type;
주석
value_type으로 선언 pair*<constkey_type, mapped_type>* 및 not pair*<key_type, mapped_type>*, 키의 결합형 컨테이너 비상수 반복기 또는 참조를 사용 하 여 변경할 수 없습니다 때문에.
예제
// multimap_value_type.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
typedef pair <const int, int> cInt2Int;
multimap <int, int> m1;
multimap <int, int> :: key_type key1;
multimap <int, int> :: mapped_type mapped1;
multimap <int, int> :: value_type value1;
multimap <int, int> :: iterator pIter;
// value_type can be used to pass the correct type
// explicitely to avoid implicit type conversion
m1.insert ( multimap <int, int> :: value_type ( 1, 10 ) );
// Compare another way to insert objects into a hash_multimap
m1.insert ( cInt2Int ( 2, 20 ) );
// Initializing key1 and mapped1
key1 = ( m1.begin( ) -> first );
mapped1 = ( m1.begin( ) -> second );
cout << "The key of first element in the multimap is "
<< key1 << "." << endl;
cout << "The data value of first element in the multimap is "
<< mapped1 << "." << endl;
// The following line would cause an error because
// the value_type is not assignable
// value1 = cInt2Int ( 4, 40 );
cout << "The keys of the mapped elements are:";
for ( pIter = m1.begin( ) ; pIter != m1.end( ) ; pIter++ )
cout << " " << pIter -> first;
cout << "." << endl;
cout << "The values of the mapped elements are:";
for ( pIter = m1.begin( ) ; pIter != m1.end( ) ; pIter++ )
cout << " " << pIter -> second;
cout << "." << endl;
}
요구 사항
헤더: <map>
네임 스페이스: std