std::map question
zero
one
unknown
two
unknown
four
five
and I wonder why.
Can anyone please let me know why 0x10 and 2 are not treated the same? Is it because they are treated as different data types? The map itself contains 6 elements, just as I would expect.
Thanks,
Richard
#include <map>
#include <string>
#include <iostream>
typedef std::map<int, std::string> INT2STRING;
INT2STRING s_enumIntToStringMap;
std::string s_unknown("unknown");
const std::string& mapIntToString( int i )
{
INT2STRING::const_iterator f = s_enumIntToStringMap.find( i );
if(f != s_enumIntToStringMap.end())
{
return (*f).second;
}// if ...
else
{
return s_unknown;
}// else
}// mapRestartModesToString()
int main(int argc, char* argv[])
{
s_enumIntToStringMap.insert(INT2STRING::value_type(0x00, "zero"));
s_enumIntToStringMap.insert(INT2STRING::value_type(0x01, "one"));
s_enumIntToStringMap.insert(INT2STRING::value_type(0x10, "two"));
s_enumIntToStringMap.insert(INT2STRING::value_type(0x11, "three"));
s_enumIntToStringMap.insert(INT2STRING::value_type(4, "four"));
s_enumIntToStringMap.insert(INT2STRING::value_type(5, "five"));
std::cout << mapIntToString( 0 ) << std::endl;
std::cout << mapIntToString( 1 ) << std::endl;
std::cout << mapIntToString( 2 ) << std::endl;
std::cout << mapIntToString( 0x10 ) << std::endl;
std::cout << mapIntToString( 3 ) << std::endl;
std::cout << mapIntToString( 4 ) << std::endl;
std::cout << mapIntToString( 5 ) << std::endl;
return 0;
}

