登录  | 立即注册

游客您好!登录后享受更多精彩

查看: 95|回复: 4

C++ Ansi转Unicode - Unicode转Ansi源码

[复制链接]

169

主题

23

回帖

1204

积分

管理员

积分
1204
发表于 2025-3-24 23:06:02 | 显示全部楼层 |阅读模式

C++ Ansi转Unicode - Unicode转Ansi源码

ANSI转unicode

 //ANSI转unicode
wchar_t* AnsiToUnicode(char *str)
{
        DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
        wchar_t *pwText;
        pwText = new wchar_t[dwNum];
        if(!pwText)
        {
                delete []pwText;
        }
        MultiByteToWideChar (CP_ACP, 0, str, -1, pwText, dwNum);
        return pwText;
}wchar_t *strUnicode = AnsiToUnicode(str);
OutputDebugStringW(strUnicode);

Unicode转ansi


//Unicode转ansi
wchar_t wText[20] = {L"宽字符转换实例!"};
 DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE);
 char *psText;
 psText = new char[dwNum];
 if(!psText)
 {
    delete []psText;
 }
 WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE);
 delete []psText;

0

主题

88

回帖

295

积分

注册会员

积分
295
发表于 2025-3-29 08:33:27 | 显示全部楼层
不错,又占了一个沙发!
回复

使用道具 举报

0

主题

210

回帖

187

积分

注册会员

积分
187
发表于 2025-4-8 10:59:45 | 显示全部楼层
学习到!!!!
回复

使用道具 举报

0

主题

12

回帖

37

积分

新手上路

积分
37
发表于 2025-4-12 08:00:42 | 显示全部楼层
看帖看完了至少要顶一下,还可以加入到淘帖哦!
回复

使用道具 举报

0

主题

8

回帖

17

积分

新手上路

积分
17
发表于 前天 05:51 | 显示全部楼层
学习学习!!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|断点社区 |网站地图

GMT+8, 2025-4-26 07:40 , Processed in 0.119381 second(s), 22 queries , Yac On.

Powered by XiunoBBS

Copyright © 2001-2025, 断点社区.

快速回复 返回顶部 返回列表