mmxingye

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

01 | windows下的字符转换

#include <stdio.h>
#include <WinSock2.h>
#include <windows.h>
//gbk -> utf-16
int test1() {
char text_gbk[256] = "砂隐村"; //字符串字面常量,取决于cpp文件自身的
wchar_t text_utf16[256] = {};
int n = MultiByteToWideChar(CP_ACP, 0, //cp_acp 当前代码页
text_gbk, strlen(text_gbk),
text_utf16, 256);
printf("结果:%d个宽字符\n", n);
return 0;
}
//gbk -> utf-16 ->utf-8
int test2() {
char text_gbk[] = "木叶村";
wchar_t text_utf16[256] = { 0 };
int n1 = MultiByteToWideChar(CP_ACP, 0,
text_gbk, strlen(text_gbk),
text_utf16, 256);
char text_utf8[256] = { 0 };
int n2 = WideCharToMultiByte(CP_UTF8, 0,
text_utf16, n1,
text_utf8, 256,
NULL,0);
printf("结果:%d个字节\n", n2);
return 0;
}
int main() {
test1();
test2();
return 0;
}

posted on   独立树  阅读(46)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
点击右上角即可分享
微信分享提示