方法一:
#include <cstdlib> int mbstowcs(wchar_t *out, const char *in, size_t size);
方法二:
#include <windows.h> int MultiByteToWideChar( [in] UINT CodePage, [in] DWORD dwFlags, [in] LPCSTR lpMultiByteStr, [in] int cbMultiByte, [out, optional] LPWSTR lpWideCharStr, [in] int cchWideChar );
範例:
catch (const std::exception& ex) { int len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, ex.what(), -1, nullptr, 0); wchar_t* wszDest = new wchar_t[len]; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, ex.what(), -1, wszDest, len); MessageBoxW(m_hwnd, wszDest, L"InitializeWindows Error", MB_OK | MB_ICONERROR); delete [] wszDest; exit(EXIT_FAILURE); }
source: How do I convert a char string to a wchar_t string?
#ansi #unicode #convert