This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
map usage woes
- To: gcc-bugs at gcc dot gnu dot org
- Subject: map usage woes
- From: Srikanth Vedire <srvedire at yahoo dot com>
- Date: Tue, 17 Jul 2001 14:44:46 -0700 (PDT)
Hello,
I seem to have a simple problem.. Why are the results
after running this program different than expected?
I get
[1] = (null) // instead of 100
[2] = 200
[3] = 300
Hopefully someone can tell me what I'm doing wrong.
I'm using 2.95.3 20010315 release of gcc.
Srikanth
#include <iostream>
#include <map>
struct ltstr
{
bool operator()(const char* s1, const char* s2)
const
{
return strcmp(s1, s2) < 0;
}
};
typedef map<const char *, const char *, ltstr>
CharCharMap;
int main(int argc, char *argv[])
{
char buff[20];
CharCharMap temp2;
buff[0] = '1';
buff[1] = '\0';
temp2[(const char *)buff] = "100";
buff[0] = '2';
buff[1] = '\0';
temp2[buff] = "200";
temp2["3"] = "300";
cout << "[1] = " << temp2["1"] << endl;
cout << "[2] = " << temp2["2"] << endl;
cout << "[3] = " << temp2["3"] << endl;
}
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/