STL map question.

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.
"asdfsd" is a char*, but the map is keyed on char.
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
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
Why aren't you using std::string to hold strings?
Topic archived. No new replies allowed.