1.wchart_t转wstring
1 wchar_t tmpRuleStr[10] = {0};
2 wstring m_tmpRuleStr = wstring(tmpRuleStr);
2.wstring转wchar_t
1 wstring str = "123";
2 wchar_t* tmp = wstr.c_str();
3.string转wstring
1 std::wstring UTF8ToUnicode(const std::string& utf)
2 {
3 wchar_t *buff = new wchar_t[utf.length()+1];
4 int len = ::MultiByteToWideChar(CP_UTF8, 0, utf.c_str(), (int)utf.length(), buff, (int)utf.length()+1);
5 std::wstring str(buff, len);
6 delete [] buff;
7 return str;
8 }
9 std::wstring AnsiToUnicode(const std::string& str)
10 {
11 wchar_t *buff = new wchar_t[str.length()+1];
12 int len = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), buff, str.length()+1);
13 std::wstring text(buff, len);
14 delete [] buff;
15 return text;
16 }
4.wstring转string
1 std::string UnicodeToUTF8(const std::wstring& str)
2 {
3 char* buff;
4 int buffersize = ::WideCharToMultiByte(CP_UTF8, 0, str.c_str(), (int)str.length(), 0, 0, 0, 0);
5 buff = new char[buffersize+1];
6 int len = ::WideCharToMultiByte(CP_UTF8, 0, str.c_str(), (int)str.length(), buff, buffersize+1, 0, 0);
7 std::string utf(buff, len);
8 delete []buff;
9 return utf;
10 }
11
12 std::string UnicodeToAnsi(const std::wstring& str)
13 {
14 char *buff;
15 int buffersize = ::WideCharToMultiByte(CP_ACP, 0, str.c_str(), str.length(), 0, 0, NULL, NULL);
16 buff = new char[buffersize+1];
17 int len = ::WideCharToMultiByte(CP_ACP, 0, str.c_str(), str.length(), buff, buffersize + 1, NULL, NULL);
18 std::string text(buff, len);
19 delete [] buff;
20 return text;
21 }
分类:
C/C++
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
2020-12-01 Gamma、Linear、sRGB 和Unity Color Space,你真懂了吗?