Problem with std::map find() method

Hi,
Would you please help me find out what is wrong with my code?

port* macro::get_port(char* myName) {
printf ("Getting port %s\n",myName);
port* hey = new port;
for (_ITER=_PORTS->begin();_ITER!=_PORTS->end();++_ITER) {
printf("Port %s existed!\n",_ITER->first);
port* tmp = _ITER->second;
printf("Port %s has direction %s\n",tmp->get_name(),tmp->get_dir());
}

if ((_ITER = _PORTS->find(myName)) == _PORTS->end())
printf("Could not find %s in map\n",myName);
else {
_ITER = _PORTS->find(myName);
printf("Port %s is found\n",_ITER->first);
}

return (hey);
}

*******************
The output is

Getting port P2
Port P2 existed!
Port P2 has direction OUTPUT
Port PA existed!
Port PA has direction OUTPUT
Port P3 existed!
Port P3 has direction INOUT
Could not find P2 in map

******************

I was able to loop through my map but was not able to find P2 port

Would you please point out what is wrong?

Thank you,
Is the key in the map a std::string?
Hi, the key is actually char*
if the key is char* it will just compare the actual pointer and not care about the string data the pointer points to. Easiest way to make it work is to use std::string as key instead.
Wow, it works. Thank you guys, I really appreciate it.
Topic archived. No new replies allowed.