How to convert std::string to LPCWSTR in C++ (Unicode)(如何在 C++ (Unicode) 中将 std::string 转换为 LPCWSTR)
本文介绍了如何在 C++ (Unicode) 中将 std::string 转换为 LPCWSTR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找将 std::string 转换为 LPCWSTR 的方法或代码片段
I'm looking for a method, or a code snippet for converting std::string to LPCWSTR
推荐答案
感谢提供指向 MSDN 文章的链接.这正是我要找的.p>
Thanks for the link to the MSDN article. This is exactly what I was looking for.
std::wstring s2ws(const std::string& s)
{
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}
std::wstring stemp = s2ws(myString);
LPCWSTR result = stemp.c_str();
这篇关于如何在 C++ (Unicode) 中将 std::string 转换为 LPCWSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何在 C++ (Unicode) 中将 std::string 转换为 LPCWSTR


基础教程推荐
猜你喜欢
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01