The map as a whole can not displayed using cout. Try
cout << *mp0_iter.first() << *mp0_iter.second() << '\n';
kbshibukumar
Junior Poster in Training
65 posts since Jan 2009
Reputation Points: 12
Solved Threads: 8
>cout << *mp0_iter.first() << *mp0_iter.second() << '\n';
This won't work, for several reasons. To begin with, first and second are not member functions. Also, the member operator binds more tightly than the indirection operator, so you're trying to call the first and second member functions (which still don't exist) on the iterator itself rather than the value type. You need to wrap the indirection in parens:
cout << (*mp0_iter).first << (*mp0_iter).second << '\n';
In sufficiently conforming versions of the standard library, the -> operator is defined and you can use that instead:
cout << mp0_iter->first << mp0_iter->second << '\n';
>mp1.insert(1,13);
>mp1.insert(2,16);
>mp1.insert(3,17);
The map class doesn't have an overload of the insert member function that takes a key/value pair as two arguments. You'd have to create your own pair object first:
mp1.insert ( make_pair ( 1, 13 ) );
mp1.insert ( make_pair ( 2, 16 ) );
mp1.insert ( make_pair ( 3, 17 ) );
But that's effort you can avoid by taking advantage of the subscript operator overload:
mp1[1] = 13;
mp1[2] = 16;
mp1[3] = 17;
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
I don't know if there is any stl hash_map. U need to use just map instead, with a #include map::iterator hmp0_iter;
maphmp0;
kbshibukumar
Junior Poster in Training
65 posts since Jan 2009
Reputation Points: 12
Solved Threads: 8