R
ravips
I have a map<char *,int> it does not work consistently. I have used
similar sort of implementation as below:
map<char *,int> m1;
map<char *,int>::iterator i;
m1["January"] = 31;
m1["February"] = 28;
m1["March"] = 31;
m1["April"] = 30;
m1["May"] = 31;
m1["June"] = 30;
m1["July"] = 31;
This is similar to the map that i have used. Now accessing this yields
different results as below:
Option1:
char *p = "May";
int it = m1[p]; // Works properly returns 31.
Option2:
char *p = new char[3];
strcpy(p, "May");
int it = m1[p]; // returns 0 .. instead of 31 ....
Can anybody help me to resolve this issue?
Thanks.
similar sort of implementation as below:
map<char *,int> m1;
map<char *,int>::iterator i;
m1["January"] = 31;
m1["February"] = 28;
m1["March"] = 31;
m1["April"] = 30;
m1["May"] = 31;
m1["June"] = 30;
m1["July"] = 31;
This is similar to the map that i have used. Now accessing this yields
different results as below:
Option1:
char *p = "May";
int it = m1[p]; // Works properly returns 31.
Option2:
char *p = new char[3];
strcpy(p, "May");
int it = m1[p]; // returns 0 .. instead of 31 ....
Can anybody help me to resolve this issue?
Thanks.