map usage woes

Srikanth Vedire srvedire@yahoo.com
Tue Jul 17 14:44:00 GMT 2001


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/



More information about the Gcc-bugs mailing list