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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CMapStringToString lookup() qestion [solved]

CMapStringToString lookup() qestion [solved]

Scheduled Pinned Locked Moved C / C++ / MFC
debugging
3 Posts 2 Posters 1 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.
  • E Offline
    E Offline
    econy
    wrote on last edited by
    #1

    I use a CMapStringToString object to store some string key-value pairs, the string are read from a Unicode text file. a.text like the following: 4001 English //space is a TAB key space 4002 German 4003 Chinese 4004 Russia then I read the text file to a CString strLine, use str1 = strLine.Tokenize(TEXT("\t"),tokenPos); to get token; str2 = strLine.Tokenize(TEXT("\t"),tokenPos); I set breakpoint, I can read the token is right,i.e. str1 = 4001/4002/4003/4004; str2 = English/German/Chinese/Russia every loop. In the loop, I use : mStrMap.SetAt(str1,str2); and after loop; mStrMap.Lookup(_T("4001"),tstStr); mStrMap.Lookup(_T("4002"),tstStr); mStrMap.Lookup(_T("4003"),tstStr); mStrMap.Lookup(_T("4004"),tstStr); The weird thing is , 4002/4003/4004 key, I got right value: German/Chinese/Russia but for 4001, I got an empty string; I thought maybe it is oxFEFF (unicode BOM), so before the loop to readline circularly, I first read BOM so as to move the file pointer back. But still, for 4001, I got an empty string. Don't know why this happened.

    L 1 Reply Last reply
    0
    • E econy

      I use a CMapStringToString object to store some string key-value pairs, the string are read from a Unicode text file. a.text like the following: 4001 English //space is a TAB key space 4002 German 4003 Chinese 4004 Russia then I read the text file to a CString strLine, use str1 = strLine.Tokenize(TEXT("\t"),tokenPos); to get token; str2 = strLine.Tokenize(TEXT("\t"),tokenPos); I set breakpoint, I can read the token is right,i.e. str1 = 4001/4002/4003/4004; str2 = English/German/Chinese/Russia every loop. In the loop, I use : mStrMap.SetAt(str1,str2); and after loop; mStrMap.Lookup(_T("4001"),tstStr); mStrMap.Lookup(_T("4002"),tstStr); mStrMap.Lookup(_T("4003"),tstStr); mStrMap.Lookup(_T("4004"),tstStr); The weird thing is , 4002/4003/4004 key, I got right value: German/Chinese/Russia but for 4001, I got an empty string; I thought maybe it is oxFEFF (unicode BOM), so before the loop to readline circularly, I first read BOM so as to move the file pointer back. But still, for 4001, I got an empty string. Don't know why this happened.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to show the exact code. And please use <pre> tags around the code blocks so it is more readable thus:

      mStrMap.Lookup(_T("4001"),tstStr);
      mStrMap.Lookup(_T("4002"),tstStr);
      mStrMap.Lookup(_T("4003"),tstStr);
      mStrMap.Lookup(_T("4004"),tstStr);

      You can automate that by selecting all the lines of code in the editor and using the code button at the top.

      E 1 Reply Last reply
      0
      • L Lost User

        You need to show the exact code. And please use <pre> tags around the code blocks so it is more readable thus:

        mStrMap.Lookup(_T("4001"),tstStr);
        mStrMap.Lookup(_T("4002"),tstStr);
        mStrMap.Lookup(_T("4003"),tstStr);
        mStrMap.Lookup(_T("4004"),tstStr);

        You can automate that by selecting all the lines of code in the editor and using the code button at the top.

        E Offline
        E Offline
        econy
        wrote on last edited by
        #3

        Sorry, it's my fault too. I read BOM, forgot to change the key string.

        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