C++ STL hash_multimap::begin() iterator program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: Using the C++ hash_multimap::begin() which return an iterator addressing the first element in the hash_multimap in C++ programming
To show: How to use the C++ hash_multimap:: begin() iterator which return an iterator addressing the first element in the hash_multimap in C++ programming
// C++ STL hash_multimap::begin() iterator
#include <hash_map>
#include <iostream>
using namespace std;
using namespace stdext;
int main()
{
// container and iterators
hash_multimap <int, int> hm1;
hash_multimap <int, int> :: iterator hm1_Iter;
hash_multimap <int, int> :: const_iterator hm1_cIter;
// simplify the pair <int, int> to Int_Pair
typedef pair <int, int> Int_Pair;
// pushing/inserting data
hm1.insert(Int_Pair(1, 3));
hm1.insert(Int_Pair(4, 1));
hm1.insert(Int_Pair(5, 9));
hm1.insert(Int_Pair(3, 3));
hm1.insert(Int_Pair(5, 7));
hm1_cIter = hm1.begin();
// print the elements
cout<<"The first element of hm1 hash multimap is "<<hm1_cIter->first<<endl;
hm1_Iter = hm1.begin();
// do the erase()
hm1.erase(hm1_Iter);
hm1_cIter = hm1.begin();
cout<<"After erase() operation, the first element of hm1 hash multimap is now "<<hm1_cIter->first<<endl;
return 0;
}
Output examples:
The first element of hm1 hash multimap is 1
After erase() operation, the first element of hm1 hash multimap is now 3
Press any key to continue . . .