0

I want to compare a LPCWSTR with a value to ensure they're equal. And I can't figure out how to compare it. I create a STRING value and tried various conversions but nothing worked. Essentially it would be:

request->id // some LPCWSTR value
STRING str = "value" // String value I want to compare
if (request->id != str)
{
 //Something
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
revitenthusiast
  • 15
  • 1
  • 1
  • 7

3 Answers3

1

Enable MFC/ATL and use the CString object:

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

Although it's not clear to me what type STRING is either. I would just use CString for both:

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

Or just use the literal directly:

if (CString(request->id) != "value")
Dan Korn
  • 1,274
  • 9
  • 14
1

Use the std::wstring type instead of a std::string in which case you have the .c_str() member function to work with or copy the string to a buffer using the MultiByteToWideChar() WinAPI function.

0

I ended up getting it to work using this process.

LPCWSTR lpc = L"STRING"; wcscmp(LPCWSTR, LPCWSTR)

revitenthusiast
  • 15
  • 1
  • 1
  • 7