博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WINDOWS下的ANSI字符串和UTF8字符串之间的相互转换
阅读量:4035 次
发布时间:2019-05-24

本文共 774 字,大约阅读时间需要 2 分钟。

//CP_ACP=ANSI,CP_UTF8=utf-8CString CXXXApp::UTF8Convert(CString &str,int sourceCodepage,int targetCodepage){int len=str.GetLength(); int unicodeLen=MultiByteToWideChar(sourceCodepage,0,str,-1,NULL,0); wchar_t * pUnicode; pUnicode=new wchar_t[unicodeLen+1]; memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t)); MultiByteToWideChar(sourceCodepage,0,str,-1,(LPWSTR)pUnicode,unicodeLen); BYTE * pTargetData; int targetLen=WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,NULL,0,NULL,NULL); pTargetData=new BYTE[targetLen+1]; memset(pTargetData,0,targetLen+1); WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)pTargetData,targetLen,NULL,NULL); CString rt; rt.Format("%s",pTargetData); delete pUnicode; delete pTargetData; return rt; }这段代码的出处忘记是哪了。修改了一下,可以使用

转载地址:http://ulfdi.baihongyu.com/

你可能感兴趣的文章
慢慢欣赏linux CPU占用率学习
查看>>
2020年终总结
查看>>
linux内核学习(4)建立正式内核的页式内存映射, 以x86 32位模式为例
查看>>
Homebrew指令集
查看>>
React Native(一):搭建开发环境、出Hello World
查看>>
React Native(二):属性、状态
查看>>
JSX使用总结
查看>>
React Native(四):布局(使用Flexbox)
查看>>
React Native(七):Android双击Back键退出应用
查看>>
Android自定义apk名称、版本号自增
查看>>
adb command not found
查看>>
Xcode 启动页面禁用和显示
查看>>
【剑指offer】q50:树中结点的最近祖先
查看>>
二叉树的非递归遍历
查看>>
【leetcode】Reorder List (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Word Break(python)
查看>>
【剑指offer】面试题26:复杂链表的复制
查看>>
【leetcode】Candy(python)
查看>>