#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main()
{
setlocale(LC_ALL, "");
char sText[] = "你好!";
//计算sText字符串的长度
DWORD dwNum = MultiByteToWideChar(CP_ACP, 0, sText, -1, NULL, 0);
printf("dwNum = %d\n", dwNum);
WCHAR pwText[100];
//转换成宽字符
MultiByteToWideChar(CP_ACP, 0, sText, -1, pwText, dwNum);
wprintf(L"%s\n", pwText);
char sText2[100];
int num = WideCharToMultiByte(CP_OEMCP, 0, pwText, -1, NULL, 0, NULL, NULL);
//转换成多字节
WideCharToMultiByte(CP_OEMCP, 0, pwText, -1, sText2, num, NULL, NULL);
printf("num:%d, sText2 = %s\n", num, sText2);
system("pause");
return 0;
}
win32 多字节、宽字符转换
最新推荐文章于 2024-03-08 10:28:51 发布