MFC中如何从Unicode到多字节的转换
2016-01-30 16:29
351 查看
std::string cStringToString(const CString& src, UINT codepage = CP_UTF8) { std::string dst; if (src.IsEmpty()) { dst.clear(); return ""; } int length = ::WideCharToMultiByte(codepage, 0, src, src.GetLength(), NULL, 0, NULL, NULL); dst.resize(length); ::WideCharToMultiByte(codepage, 0, src, src.GetLength(), &dst[0], (int)dst.size(), NULL, NULL); return dst; } CString stringToCString(const std::string& src, UINT codepage = CP_UTF8) { CString dst; if (src.empty()) { return dst; } int length = ::MultiByteToWideChar(codepage, 0, src.data(), (int)src.size(), NULL, 0); WCHAR* pBuffer = dst.GetBufferSetLength(length); ::MultiByteToWideChar(codepage, 0, src.data(), (int)src.size(), pBuffer, length); return dst; }
然后怎么实现CString转LPWSTR
LPWSTR = (LPWSTR)(LPCWSTR)CString
相关文章推荐
- git rebase 后找回消失的commit
- 关于闭包与for循环的理解
- Handlebars.js 模板引擎
- 自定义ImageView实现地图(一)
- 设计模式六大原则之Liskov替换原则
- LVS负载均衡介绍
- mysql index
- H-Index
- git add时候报错:LF will be replaced by CRLF
- 100. SimpleXML
- android webview用法小结
- ubuntu如何分区
- poj1308
- 层叠样式表——CSS
- HDU 1069 I Think I Need a Houseboat(模拟)
- MySQL复制的三种架构
- Vim加入文档声明信息
- 【Linux入门学习之】vi/vim编辑器必知必会
- 用C语言编写杨辉三角
- openstack学习笔记(一)-openstack的基础知识