我在下面定义了一个 TCHAR:
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
我想如下:
if(szProcessName == "NDSClient.exe")
{
}
但后来我得到了错误:
错误 C2446:==:没有从 const char * 转换为 TCHAR *
错误 C2440:“==”:无法从“const char [14]”转换为“TCHAR [260]”
"NDSClient.exe"
是const char*
windows 上的字符串。如果你想让它成为一个const TCHAR*
那么你需要使用TEXT
宏。此外,您不能==
使用等价TCHAR
函数来比较字符串,例如_tcscmp
.
你也可以使用。L"some string"
制作 TCHAR*。但我建议您使用std::wstring
(analog of std::string
and as std::string
needs #include <string>
) 而不是 TCHAR*。
例子:
#include <windows.h>
#include <string>
#include <iostream>
using namespace std;
int main()
{
wstring s = TEXT("HELLO");
wstring ss = L"HELLO";
if(s == ss)
cout << "hello" << endl;
return 0;
}