【问题标题】:convert a STRING from LPCWSTR and vice versa c++从 LPCWSTR 转换字符串,反之亦然 c++
【发布时间】:2016-09-12 21:12:41
【问题描述】:
我想将 LPCWSTR 与一个值进行比较,以确保它们相等。而且我不知道如何比较它。我创建了一个 STRING 值并尝试了各种转换,但没有任何效果。本质上是:
request->id // some LPCWSTR value
STRING str = "value" // String value I want to compare
if (request->id != str)
{
//Something
}
【问题讨论】:
标签:
c++
string
visual-studio
lpcwstr
【解决方案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")
【解决方案3】:
我最终使用这个过程让它工作。
LPCWSTR lpc = L"字符串";
wcscmp(LPCWSTR, LPCWSTR)