0
#include<iostream>
#include<map>

using namesapce std;
void main()
{
   map<const TCHAR*, int> Map;
   Map.insert(make_pare(L"DOG1",1));
   Map.insert(make_pare(L"DOG2",2));

   TCHAR szTem[128];
   wsprintf(szTem,L"DOG%d",1);

   map<const TCHAR*, int>::iterator iter = Map.find(szTem);

   cout << iter->second << endl;
}

Like this case, I couldn't find TCHAR* Keyvalue using TCHAR[]. Why i can't do this, and how can i find pointer string Keyvalue using string that include integer fomula?

Ari0nhh
  • 5,720
  • 3
  • 28
  • 33
Bback.Jone
  • 61
  • 5
  • 1
    because the comparison operator `<` isn't defined for TCHAR* to dereference the pointer and compare string values, it's going to compare the pointer address values which is incorrect. You need to define the comparator or use `std::string` is there a reason you need to use `TCHAR` here? – EdChum Nov 14 '16 at 15:09
  • You didn't define `TCHAR`. If you use non-standard features, you should tell us which os/compiler/standard library you are targetting. `void main` is not standard either. – eerorika Nov 14 '16 at 15:16

1 Answers1

2

You can not do that, because default map comparator will compare TCHAR pointers, which of course would be different. Best approach would be to use std::wstring instead. If you insist on using TCHAR pointer, you have to provide custom comparator.

Community
  • 1
  • 1
Ari0nhh
  • 5,720
  • 3
  • 28
  • 33