C
Clint Weisbrod
All,
I'm creating an STL map object like this:
map<double, string> myMap;
I add a few items to the map using the [] operator.
If I iterate over the map like:
map<double, string>::iterator it, itLast;
for (it = myMap.begin(); it != myMap.end(); ++it)
{
itLast = it;
}
Then itLast should reference the last item in the map, (the item with
largest key). This works fine. My problem is if I do the following:
map<double, string>::iterator itLast2 = myMap.end();
--itLast2;
Then itLast2 does not reference the same item in the map. In fact, it
always ends up referencing the first item (with smallest key)!
Now I thought that using a double type key would be a problem, but
after researching this a bit, using double types (although probably
not a good idea) should work the way I expect.
Has anyone come across a similar problem?
Thanks everyone.
Clint Weisbrod.
I'm creating an STL map object like this:
map<double, string> myMap;
I add a few items to the map using the [] operator.
If I iterate over the map like:
map<double, string>::iterator it, itLast;
for (it = myMap.begin(); it != myMap.end(); ++it)
{
itLast = it;
}
Then itLast should reference the last item in the map, (the item with
largest key). This works fine. My problem is if I do the following:
map<double, string>::iterator itLast2 = myMap.end();
--itLast2;
Then itLast2 does not reference the same item in the map. In fact, it
always ends up referencing the first item (with smallest key)!
Now I thought that using a double type key would be a problem, but
after researching this a bit, using double types (although probably
not a good idea) should work the way I expect.
Has anyone come across a similar problem?
Thanks everyone.
Clint Weisbrod.