hash_multimap::value_type
注意事項 |
---|
這個 API 已經過時。替代案例是 unordered_multimap 類別。 |
表示物件的型別。hash_multimap 儲存。
typedef pair<const Key, Type> value_type;
備註
使用非常數 Iterator 或參考,,,因為關聯的容器的金鑰不可以變更value_type 宣告為 pair*<const key_type,而不是 mapped_type>pair<則為key_type,* 否則為mapped_type*>。*
在 Visual C++ .NET 2003 中, <hash_map> 和 <hash_set> 標頭檔的成員不在 std 命名空間中,而是移至 stdext 命名空間。 如需詳細資訊,請參閱 stdext 命名空間。
範例
// hash_multimap_value_type.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
typedef pair <const int, int> cInt2Int;
hash_multimap <int, int> hm1;
hash_multimap <int, int> :: key_type key1;
hash_multimap <int, int> :: mapped_type mapped1;
hash_multimap <int, int> :: value_type value1;
hash_multimap <int, int> :: iterator pIter;
// value_type can be used to pass the correct type
// explicitely to avoid implicit type conversion
hm1.insert ( hash_multimap <int, int> :: value_type ( 1, 10 ) );
// Compare another way to insert objects into a hash_multimap
hm1.insert ( cInt2Int ( 2, 20 ) );
// Initializing key1 and mapped1
key1 = ( hm1.begin( ) -> first );
mapped1 = ( hm1.begin( ) -> second );
cout << "The key of first element in the hash_multimap is "
<< key1 << "." << endl;
cout << "The data value of first element in the hash_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 = hm1.begin( ) ; pIter != hm1.end( ) ; pIter++ )
cout << " " << pIter -> first;
cout << "." << endl;
cout << "The values of the mapped elements are:";
for ( pIter = hm1.begin( ) ; pIter != hm1.end( ) ; pIter++ )
cout << " " << pIter -> second;
cout << "." << endl;
}
需求
標頭檔: <hash_map>
**命名空間:**stdext