0

我想将 LPCWSTR 与一个值进行比较,以确保它们相等。而且我不知道如何比较它。我创建了一个 STRING 值并尝试了各种转换,但没有任何效果。本质上它将是:

request->id // some LPCWSTR value
STRING str = "value" // String value I want to compare
if (request->id != str)
{
 //Something
}
4

3 回答 3

1

启用 MFC/ATL 并使用 CString 对象:

if (CString(request->id) != str)

虽然我也不清楚 STRING 是什么类型。我只会对两者都使用 CString :

STRING str = "value" // String value I want to compare
if (CString(request->id) != str)

或者直接使用文字:

if (CString(request->id) != "value")
于 2016-09-12T21:37:53.083 回答
1

使用std::wstring类型而不是 std::string 在这种情况下,您可以使用.c_str()成员函数使用MultiByteToWideChar() WinAPI 函数将字符串复制到缓冲区。

于 2016-09-12T22:08:33.007 回答
0

我最终使用这个过程让它工作。

LPCWSTR lpc = L“字符串”;wcscmp(LPCWSTR, LPCWSTR)

于 2016-09-12T21:57:24.887 回答