Newbie Maps Question
Why does the top code work but the bottom one complains about << with the planets map. << planets.find(1)->second
// print content:
cout << "elements in mymap:" << endl;
cout << "c => " << mymap.find('c')->second << endl;
cout << "p => " << planets.find(1)->second << endl;
What is the 'complaint' you get exactly?
Both of those compile and run fine for me.
no operator "<<" matches these operands
What, well are you paying by the word to post or something?
Anyhow it compiles and runs fine, did you include <map> and <iostream>, namespace std; maybe?
Have included them... using vis studio 2010 not my usual software...
Your forgot to #include<string> on your second example would be my guess.
Thanks! Sorry I have never written anything in C++(Java Girl)I dont know most of the syntax. But someone wanted this done in C so.... xD
I hope they wanted it done in C++; because you are not writing C code when you use ">>" or "<<" for input/output.
Originally Posted by Scotty12
I would certainly hope so too, because the STL isn't C either.....:tongue:
On a side note, I would recommend using map::insert() for insertion instead of operator  for std::maps.
It would also be a good idea if find succeeds or not. It doesn't throw an exception if it fails, so if it fails, you will try to dereference an invalid iterator and get undefined behavior.