c++ ANSI、UNICODE、UTF8互转
    static std::wstring MBytesToWString(const char* lpcszString);
    static std::string WStringToMBytes(const wchar_t* lpwcszWString);
    static std::wstring UTF8ToWString(const char* lpcszString);
    static std::string WStringToUTF8(const wchar_t* lpwcszWString);
std::wstring KKLogObject::MBytesToWString(const char* lpcszString)
{
    int len = strlen(lpcszString);
    int unicodeLen = ::MultiByteToWideChar(CP_ACP, 0, lpcszString, -1, NULL, 0);
    wchar_t* pUnicode = new wchar_t[unicodeLen + 1];
    memset(pUnicode, 0, (unicodeLen + 1) * sizeof(wchar_t));
    ::MultiByteToWideChar(CP_ACP, 0, lpcszString, -1, (LPWSTR)pUnicode, unicodeLen);
    wstring wString = (wchar_t*)pUnicode;
    delete [] pUnicode;
    return wString;
}

std::string KKLogObject::WStringToMBytes(const wchar_t* lpwcszWString)
{
    char* pElementText;
    int iTextLen;
    // wide char to multi char
    iTextLen = ::WideCharToMultiByte(CP_ACP, 0, lpwcszWString, -1, NULL, 0, NULL, NULL);
    pElementText = new char[iTextLen + 1];
    memset((void*)pElementText, 0, (iTextLen + 1) * sizeof(char));
    ::WideCharToMultiByte(CP_ACP, 0, lpwcszWString, 0, pElementText, iTextLen, NULL, NULL);
    std::string strReturn(pElementText);
    delete [] pElementText;
    return strReturn;
}

std::wstring KKLogObject::UTF8ToWString(const char* lpcszString)
{
    int len = strlen(lpcszString);
    int unicodeLen = ::MultiByteToWideChar(CP_UTF8, 0, lpcszString, -1, NULL, 0);
    wchar_t* pUnicode;
    pUnicode = new wchar_t[unicodeLen + 1];
    memset((void*)pUnicode, 0, (unicodeLen + 1) * sizeof(wchar_t));
    ::MultiByteToWideChar(CP_UTF8, 0, lpcszString, -1, (LPWSTR)pUnicode, unicodeLen);
    wstring wstrReturn(pUnicode);
    delete [] pUnicode;
    return wstrReturn;
}

std::string KKLogObject::WStringToUTF8(const wchar_t* lpwcszWString)
{
    char* pElementText;
    int iTextLen = ::WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)lpwcszWString, -1, NULL, 0, NULL, NULL);
    pElementText = new char[iTextLen + 1];
    memset((void*)pElementText, 0, (iTextLen + 1) * sizeof(char));
    ::WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)lpwcszWString, -1, pElementText, iTextLen, NULL, NULL);
    std::string strReturn(pElementText);
    delete [] pElementText;
    return strReturn;
}

c++ ANSI、UNICODE、UTF8互转相关推荐

  1. 字符串处理 - ANSI - Unicode - UTF8 转换

    字符串处理 - ANSI - Unicode - UTF8 转换 [C语言]字符串处理 - ANSI - Unicode - UTF8 转换 2008-11-4: 使用MultiByteToWideC ...

  2. 字符编码 ansi unicode utf-8 区别

    简介 为使计算机支持更多语言,通常使用 0x80~0xFFFF 范围的 2 个 字节来表示 1 个字符.比如:汉字 '中' 在 ANSI编码 中文操作系统中,使用 [0xD6,0xD0] 这两个字节存 ...

  3. 字符编码详解及由来(UNICODE,UTF-8,GBK)

    字符编码详解及由来(UNICODE,UTF-8,GBK) 各种字符编码方式详解及由来(ANSI,UNICODE,UTF-8,GB2312,GBK) - 2009-01-29 09:53     一直对 ...

  4. 统计“3_人民日报语料”文本中的字符数和词数,把文件分别保存为 ansi, UTF8,UTF16,unicode 格式

    统计"3_人民日报语料"文本中的字符数和词数,把文件分别保存为 ansi, UTF8,UTF16,unicode 格式; 首先,统计文件的字符数,有两种方法.第一种是将文件复制到w ...

  5. 趣谈unicode,ansi,utf-8,unicode big endian这些编码有什么区别

    从头讲讲编码的故事.那么就让我们找个草堆坐下,先抽口烟,看看夜晚天空上的银河,然后想一想要从哪里开始讲起.嗯,也许这样开始比较好-- 很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同 ...

  6. 介绍一下unicode,ansi,utf-8,unicode big endian编码

    介绍一下unicode,ansi,utf-8,unicode big endian编码 很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以表示世界上的万物.他们看到8个开关状 ...

  7. 字符集和编码 UNICODE、ANSI、UTF-8、GB2312 都是什么鬼

    这是我在网上看到的一篇通俗易懂的教程,但是无法找到原作者的署名,故直接搬过来了 不是本人所作,特此声明 快下班时,爱问问题的小朋友Nico又问了一个问题: "sqlserver里面有char ...

  8. ASCII,unicode, utf8 ,big5 ,gb2312,gbk,gb18030等几种常用编码区别

    ASCII,unicode, utf8 ,big5 ,gb2312,gbk,gb18030等几种常用编码区别 最近老为编码问题而烦燥,下定决心一定要将其弄明白!本文主要总 结网上一些朋友提供的 asc ...

  9. 初识编码 gbk unicode utf-8

    初识编码 gbk unicode utf-8 1. ascii 8bit 1byte(字节) 256个码位 只用到了7bit, 用到了前128个 最前面的一位是0 2. 中国人自己对计算机编码进行统计 ...

最新文章

  1. php实时股票,php获得股票数据
  2. 想写点什么留下点念想
  3. Linux基础命令---more
  4. ECCV 2012 KCF/DCF:《High-speed tracking with kernelized correlation filters》论文笔记
  5. 服务器端发送邮件签名采用Data URI scheme包含图片
  6. python数据分析的例子_Python数据分析案例—商圈客流量特征分析
  7. 15个国外最佳免费图片素材网站,快让小伙伴都知道
  8. Android流量统计分析
  9. java计算机毕业设计临大新生入学指导系统源代码+数据库+系统+lw文档
  10. 计算机软件工程学校二本大学,“软件工程专业”实力较强的二本大学,高考分数不理想报考合适...
  11. VB6.0安装鼠标滚轮
  12. Mysql 页分裂页合并
  13. 路由器无法服务器未响应是怎么回事,路由器设置时服务器未响应怎么回事
  14. html中标签的src属性值,HTML frame 标签的 src 属性
  15. 无人机机械臂爪机器臂爪的安装调试试验。以大疆哪吒为例乐迪T8Fb遥控器。
  16. Qt之QComboBox 解决下拉列表样式不生效、item文字重叠
  17. 从程序员到项目经理(9):程序员加油站 --要执着但不要固执
  18. JavaScript基础整理(配代码及注释)
  19. 服务器测压网站,网站服务器压力测试
  20. java计算机毕业设计技术交流网站源程序+mysql+系统+lw文档+远程调试

热门文章

  1. 伪造http请求救急
  2. python工具用什么语言_Python中一些自然语言工具的使用的入门教程
  3. c++ 输出二进制_C语言 printf 格式化输出的详细示例
  4. 谈java的导入(import)
  5. 转 db_file_multiblock_read_count
  6. ARM公司推出AI与机器学习用新型微处理器
  7. WPF-DataContext
  8. Fragment与Acitvity通信
  9. 搭建DNS域名解析服务器
  10. noSql-redis