[英]convert a STRING from LPCWSTR and vice versa c++
我想將LPCWSTR與一個值進行比較,以確保它們相等。 而且我不知道如何比較它。 我創建了一個STRING值,並嘗試了各種轉換,但沒有任何效果。 本質上是:
request->id // some LPCWSTR value
STRING str = "value" // String value I want to compare
if (request->id != str)
{
//Something
}
啟用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")
使用std :: wstring類型而不是std :: string類型,在這種情況下,您可以使用.c_str()
成員函數使用MultiByteToWideChar() WinAPI函數將字符串復制或復制到緩沖區中。
我最終使它在此過程中起作用。
LPCWSTR lpc = L“ STRING”; wcscmp(LPCWSTR,LPCWSTR)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.