Something wrong with Map iterator...

map<int, string> mars;
mars[1]="something1";
mars[2]="something2";
mars[123]="something123";
for (int i=500; i<ephemeris_time.size(); i++)
{
if (mars.find(marsV[i])!=mars.end())
{
cout << marsV[i] << " " << mars.find(marsV[i])->second << endl;
};
};

Dear all,
I cannot compile this code. marsV is a vector of int fed in from elsewhere of the program.
My problem is - I suppose mars.find(some int) is supposed to return the iterator that points to the correct element in the map, if the element is not in the map, then the returned iterator will point to mars.end(); but anyhow it will return an iterator.
And so I want to use this returned iterator to further return the string element attached to the map int key. Hence, mars.find(marsV[i])->second. However, the compiler would not allow me to do this.
Can anyone tell me what's wrong? Thanks.
Regards,
Bosco
Last edited on
Oh Hold... It maybe some bug elsewhere in the program... Hold on...
Topic archived. No new replies allowed.