I have an alarmingly strange situation. I fill my map with const char * and int values. When I try to "find" the one I want, it says it's not there. Here's the short version:
// tempText = "socialize"
for( actionIter =actionMap.begin(); actionIter !=actionMap.end(); ++actionIter )
{
if ( !strcmp( actionIter->first, "socialize" ) )
{
print( "it reaches this point" );
if ( !strcmp( actionIter->first, tempText ) ) // check if they're the same
print( "it reaches this point too, they're the same" );
iter =actionMap.find( tempText ) );
if ( iter == actionMap.end() )
print( "always hits this" );
// so there's no "socialize" in the map (there is!)
iter = actionMap.find( actionIter->first );
if ( iter == actionMap.end() )
print( "never hits this" );
else
print( "always hits this" );
// but I already proved that tempText == actionIter->first!
//how can this be found and tempText not?
iter = actionMap.find( "socialize" );
if ( iter == actionMap.end() )
print( "always reaches this" );
// claiming it doesn't find the very thing that let it into the if statement
}
}
There's no threading or garbage collection going on. I thought it might have something to do with my changing of wchar to const char * when populating the map:
// this is inefficient but I did it for clarity during bug finding
const char* strcpy_wcr( const WCHAR *src )
{
char* temp;
const WCHAR* ptrSrc = src;
int i = 0;
while ( *ptrSrc )
i++;
char *temp = (char *)malloc( i + 1 ); // 1 for \0
char *ptrTemp = temp;
while (*src)
*ptrTemp++ = *src++;
*ptrTemp = 0;
return static_cast<const char *>( temp );
}
//and the map is populated with this line
actionMap.insert( std::pair<const char*, int>( strcpy_wcr( pwszValue ), atoi( strText ) ) );
//where pwszValue is a const WCHAR *
Any ideas?