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. C / C++ / MFC
  4. Probelm with std::ma find function

Probelm with std::ma find function

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmshelpquestion
4 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.
  • L Offline
    L Offline
    Lakshmi_p
    wrote on last edited by
    #1

    Hello everyone, I am using std::map in my application. I am searching for CMyStruct based on the CString using find function. But sometimes find function is returning null iterator even when there is strcture obj with specified key. Can anyone help me in finding the solution?

    C R 2 Replies Last reply
    0
    • L Lakshmi_p

      Hello everyone, I am using std::map in my application. I am searching for CMyStruct based on the CString using find function. But sometimes find function is returning null iterator even when there is strcture obj with specified key. Can anyone help me in finding the solution?

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Posting the relevant code would possibly help. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      L 1 Reply Last reply
      0
      • L Lakshmi_p

        Hello everyone, I am using std::map in my application. I am searching for CMyStruct based on the CString using find function. But sometimes find function is returning null iterator even when there is strcture obj with specified key. Can anyone help me in finding the solution?

        R Offline
        R Offline
        Roger Stoltz
        wrote on last edited by
        #3

        Lakshmi_p wrote:

        sometimes find function is returning null iterator even when there is strcture obj with specified ke

        Umm, that's odd. If the key doesn't exist in the sequence std::map::find() returns end() and not NULL. Have you verified that you haven't added a NULL pointer for the key you're looking for? If the answer to this question is 'no', don't bother answering the following. ;-) How have you declared your map? Post some code (preferrably properly formatted using <pre></pre> tags) How do you add elements to the sequence? (Code again)

        "It's supposed to be hard, otherwise anybody could do it!" - selfquote
        "High speed never compensates for wrong direction!" - unknown

        1 Reply Last reply
        0
        • C CPallini

          Posting the relevant code would possibly help. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          L Offline
          L Offline
          Lakshmi_p
          wrote on last edited by
          #4

          Hi, here is how I used std::mapmapVar; void Myfun1() { ... CString strTemp = "str1"; mapVar[strTemp] = myStructObj1; } void MyFun2() { map<CString, CMyStruct>::const_iterator itr; Cstring strTemp = "str1"; itr = mapVar.find(strTemp); .... } Sometimes it is working fine but sometimes it is not working.

          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