在CEGUI中为了显示中文,常常需要将string转换为wstring,在网上查找了好几种方法,发现有的转换不了汉字,有的函数抽风,转换过来都是空的。最终还是找到了解决问题的办法,拿出来共享一下:
std::wstring StringToWString(const std::string& s)
{
std::wstring wszStr;
int nLength = MultiByteToWideChar( CP_ACP, 0, s.c_str(), -1, NULL, NULL );
wszStr.resize(nLength);
LPWSTR lpwszStr = new wchar_t[nLength];
MultiByteToWideChar( CP_ACP, 0, s.c_str(), -1, lpwszStr, nLength );
wszStr = lpwszStr;
delete [] lpwszStr;
return wszStr;
}
好不好谁用谁知道啊!
本文提供了一种在CEGUI中实现中文显示的有效方法,通过将std::string转换为wstring来解决汉字显示问题。该方法利用了MultiByteToWideChar函数进行编码转换。
3834

被折叠的 条评论
为什么被折叠?



