C++中の文字列の操作--幅の狭い文字の変換の実例は詳しく説明します。
C++中の文字列の操作--幅の狭い文字の変換の実例は詳しく説明します。
MultiByteToWideChar
MultiByteToWideChar
int MultiByteToWideChar(
_In_ UINT CodePage,
_In_ DWORD dwFlags,
_In_ LPCSTR lpMultiByteStr,
_In_ int cbMultiByte,
_Out_opt_ LPWSTR lpWideCharStr,
_In_ int cchWideChar
);
:
CodePage: CP_ACP、CP_UTF8
dwFlags:0
lpMultiByteStr [in]:
。
cbMultiByte [in]:
lpMultiByteStr " " 。
0, ;
-1, , \0 , \0 , \0 ;
>0, \0, 。
lpWideCharStr [out, optional]:
。
cchWideChar [in]:
lpWideCharStr " " 。
0, lpWideCharStr , " " 。
コード:
int requiredBufSize = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
if (requiredBufSize > 0)
{
WCHAR *pBuffer = new WCHAR[requiredBufSize];
MultiByteToWideChar(CP_ACP, 0, src, -1, pBuffer, requiredBufSize);
}
WideChar ToMultiByte
int WideCharToMultiByte(
_In_ UINT CodePage,
_In_ DWORD dwFlags,
_In_ LPCWSTR lpWideCharStr,
_In_ int cchWideChar,
_Out_opt_ LPSTR lpMultiByteStr,
_In_ int cbMultiByte,
_In_opt_ LPCSTR lpDefaultChar,
_Out_opt_ LPBOOL lpUsedDefaultChar
);
:
lpDefaultChar [in, optional]:NULL
lpUsedDefaultChar [out, optional]:NULL
MultiByteToWideChar
コード:
int requiredBufSize = WideCharToMultiByte(CP_ACP, 0, src, -1, NULL, 0, NULL, NULL);
if (requiredBufSize > 0)
{
char *pBuffer = new char[requiredBufSize];
WideCharToMultiByte(CP_ACP, 0, src, -1, pBuffer, requiredBufSize, NULL, NULL);
}
疑問があれば、メッセージをお願いします。あるいは、当駅のコミュニティで交流して討論してください。ありがとうございます。