STL map question.

Apr 21, 2011 at 10:47am
Hello everyone,

I have declared a map :
map<char,int> mymap;

and when I say
map["asdfsd"]=5;
it throws an error : 58: error: invalid conversion from `char*' to `char'

how can I get around this ? I mean having a string as a key and not just a single character ?

Thanks.
Apr 21, 2011 at 10:50am
"asdfsd" is a char*, but the map is keyed on char.
Apr 21, 2011 at 10:52am
yeah but i can't declare
map<char[20],int> so how can I do this, if it is possible ?

edit: nevermind I used string instead of char.
Last edited on Apr 21, 2011 at 11:16am
Apr 21, 2011 at 11:26am
http://www.experts-exchange.com/Programming/Languages/CPP/Q_23253032.html shows a sample implementation.

Actually you will have to write a comparator i.e. overloaded () function to be able to char* as a map key ;)

-Kush
Apr 21, 2011 at 1:08pm
Why aren't you using std::string to hold strings?
Topic archived. No new replies allowed.