Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. std::map key std::basic_string<TCHAR> - How to achieve case in-sensitive string lookup ? [modified]

std::map key std::basic_string<TCHAR> - How to achieve case in-sensitive string lookup ? [modified]

Scheduled Pinned Locked Moved ATL / WTL / STL
c++helptutorialquestionworkspace
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anand_study
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • A anand_study

      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

      S Offline
      S Offline
      Sceptic Mole
      wrote on last edited by
      #2

      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[^]

      A 1 Reply Last reply
      0
      • S Sceptic Mole

        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[^]

        A Offline
        A Offline
        anand_study
        wrote on last edited by
        #3

        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

        S S 2 Replies Last reply
        0
        • A anand_study

          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

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          yes

          1 Reply Last reply
          0
          • A anand_study

            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

            S Offline
            S Offline
            Sceptic Mole
            wrote on last edited by
            #5

            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 of stricmp, see: http://msdn2.microsoft.com/en-us/library/k59z8dwe(VS.80).aspx[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups