Hi All
I am trying to insert values in map as <char*,int> .
The key is combination of 2 numbers which is generated in code.
The problem is when I am trying to get count of that key, it is giving me 0.
Below is sample code.
Code:
#include <iostream>
#include <map>
using namespace std;
int main ()
{
std::map<char*,int> mp;
char key[10] = {0x00};
char mapKey[10] = {0x00};
sprintf(key,"%d%d",0,0);
mp.insert(std::pair<char*,int>(key,4));
sprintf(mapKey,"%d%d",0,0);
int count = mp.count(mapKey);
if ( count > 0 )
cout<<"\n Key Found";
else
cout <<"\n Not found\n";
std::map<char*,int>::iterator it;
// This is printing correct values of map
for (it=mp.begin(); it!=mp.end(); ++it)
std::cout << it->first << " => " << it->second << '\n';
getchar();
}
OutPut: Not Found
00=> 4
So map has value but count() is failing.
Can any body help me here.
Thanks
Bhagwat