当前位置: 首页 > news >正文

c++简体中文与繁体中文互转

项目需要,简体中文转换成繁体中文;

void MyTemporayIdea::Simplified2Traditional()
{const std::wstring& strSrc = L"中文繁体:中华人民共和国";std::wstring strDest(strSrc.length() + 1, 0);LCMapStringW(0x0804, LCMAP_TRADITIONAL_CHINESE, strSrc.data(), strSrc.length(), (LPWSTR)strDest.data(), strDest.length());QMessageBox::information(this, "", QString::fromStdWString(strDest));
}

 

以下来自:https://zhuanlan.zhihu.com/p/596979492

繁体中文转简体中文UNICODE版本

wstring Traditional::ToSimple(const wstring & _str)
{LPCWSTR lpSrcStr = _str.c_str();int cchSrc = static_cast<int>(_str.size());int cchDest = static_cast<int>(1+_str.size());LPWSTR lpDestStr = new WCHAR[cchDest]{0};LCMapStringW(0x0804,LCMAP_SIMPLIFIED_CHINESE,lpSrcStr,cchSrc,lpDestStr,cchDest);wstring str(lpDestStr);delete[] lpDestStr;lpDestStr = nullptr;return str;
}

简体中文转繁体中文UNICODE版本

wstring Traditional::FromSimple(const wstring & _str)
{LPCWSTR lpSrcStr = _str.c_str();int cchSrc = static_cast<int>(_str.size());int cchDest = static_cast<int>(1+_str.size());LPWSTR lpDestStr = new WCHAR[cchDest]{0};LCMapStringW(0x0804,LCMAP_TRADITIONAL_CHINESE,lpSrcStr,cchSrc,lpDestStr,cchDest);wstring str(lpDestStr);delete[] lpDestStr;lpDestStr = nullptr;return str;
}

http://www.mrgr.cn/news/38179.html

相关文章:

  • 智尚招聘求职小程序V1.0.17
  • 【算法】字符串相关
  • 【Linux】Linux环境基础开发工具使用
  • 小徐影院:探索Spring Boot的影院管理
  • python开发讯飞星火
  • 设计模式-策略模式-200
  • 华为 HCIP-Datacom H12-821 题库 (29)
  • VS Code 配置 Anaconda Python 环境
  • 【洛谷】AT_abc178_e [ABC178E] Dist Max 的题解
  • Vue和axios零基础学习
  • 使用ESPnet的 setup_anaconda.sh安装脚本一步到位,配置conda虚拟环境
  • 言语理解(2)
  • 【反素数】
  • 2024年云南省职业院校技能大赛-云计算应用
  • 一些硬件知识(二十五)
  • 这种膜为啥能随温度变透明?怎么制备的?有啥特点?
  • Synchronized和 ReentrantLock有什么区别?
  • 音视频入门基础:FLV专题(7)——Tag header简介
  • 云原生之容器编排实践-OpenEuler23.09离线安装Kubernetes与KubeSphere
  • 0基础学前端 day6 -- 搭建github pages静态网址