C++, WCHAR[] to std::cout and comparision

migajek picture migajek · Oct 26, 2009 · Viewed 8.6k times · Source

I need to put WCHAR[] to std::cout ... It is a part of PWLAN_CONNECTION_NOTIFICATION_DATA passed from Native Wifi API callback.

I tried simply std::cout << var; but it prints out the numeric address of first char. the comparision (var == L"some text") doesn't work either. The debugger returns the expected value, however the comparision returns 0. How can I convert this array to a standard string(std::string)?

Thanks in advance

Answer

&#201;ric Malenfant picture Éric Malenfant · Oct 26, 2009

Some solutions:

  • Write to std::wcout instead
  • Convert:
    • The standard way, using std::codecvt
    • The Win32 way, using WideCharToMultibyte