我有一个TCHAR定义如下:
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
Run Code Online (Sandbox Code Playgroud)
我想如下:
if(szProcessName == "NDSClient.exe")
{
}
Run Code Online (Sandbox Code Playgroud)
但后来我得到了错误:
错误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(模拟std::string和std::string需要#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;
}
Run Code Online (Sandbox Code Playgroud)