std::map key std::basic_string<TCHAR> - How to achieve case in-sensitive string lookup ? [modified]
-
I need to use std::map with std::basic_string<TCHAR> as key and long as value. std::map<std::basic_string<TCHAR> , long> myMap; How to achieve/implement case in-sensitive string lookup ? My Environment is -> VC++6, MFC, Win98/2000/NT/2003/XP I truly appreciate any help/hint. Thanks Anand_Arv -- modified at 6:48 Friday 9th February, 2007
-
I need to use std::map with std::basic_string<TCHAR> as key and long as value. std::map<std::basic_string<TCHAR> , long> myMap; How to achieve/implement case in-sensitive string lookup ? My Environment is -> VC++6, MFC, Win98/2000/NT/2003/XP I truly appreciate any help/hint. Thanks Anand_Arv -- modified at 6:48 Friday 9th February, 2007
Anand_Arv wrote:
I need to use std::map with std::basic_string(TCHAR) as key and long as value. std::basic_string How to achieve/implement case in-sensitive string lookup ?
You need to add a Compare argument:
map <basic_string<TCHAR>, long, ltstr> mymap;
Where lstr could be defined as:
struct ltstr
{
bool operator()(const basic_string<TCHAR>& s1, const basic_string<TCHAR>& s2) const
{
return stricmp (s1.c_str(), s2.c_str()) < 0;
}
};See also: http://www.sgi.com/tech/stl/Map.html[^]
-
Anand_Arv wrote:
I need to use std::map with std::basic_string(TCHAR) as key and long as value. std::basic_string How to achieve/implement case in-sensitive string lookup ?
You need to add a Compare argument:
map <basic_string<TCHAR>, long, ltstr> mymap;
Where lstr could be defined as:
struct ltstr
{
bool operator()(const basic_string<TCHAR>& s1, const basic_string<TCHAR>& s2) const
{
return stricmp (s1.c_str(), s2.c_str()) < 0;
}
};See also: http://www.sgi.com/tech/stl/Map.html[^]
Thanks a lot for helping. If I use that compare argument as you suggested, Will I get the same result for all of the following ? // assume that "ABC" (string key) and 101 (long value) is added to mymap mymap.find("Abc") mymap.find("ABC") mymap.find("abc") mymap.find("aBC") Anand_Arv
-
Thanks a lot for helping. If I use that compare argument as you suggested, Will I get the same result for all of the following ? // assume that "ABC" (string key) and 101 (long value) is added to mymap mymap.find("Abc") mymap.find("ABC") mymap.find("abc") mymap.find("aBC") Anand_Arv
yes
-
Thanks a lot for helping. If I use that compare argument as you suggested, Will I get the same result for all of the following ? // assume that "ABC" (string key) and 101 (long value) is added to mymap mymap.find("Abc") mymap.find("ABC") mymap.find("abc") mymap.find("aBC") Anand_Arv
Anand_Arv wrote:
If I use that compare argument as you suggested, Will I get the same result for all of the following ?
You probably should use
_tcsicmp
instead ofstricmp
, see: http://msdn2.microsoft.com/en-us/library/k59z8dwe(VS.80).aspx[^]