游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1239|回复: 0

string 到 wstring的转换

[复制链接]

4

主题

4

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2009-8-12 14:58:00 | 显示全部楼层 |阅读模式
   在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;
}
        好不好谁用谁知道啊!
本文来自新浪博客,转载请标明出处:http://blog.sina.com.cn/s/blog_613d5bdc0100er4g.html
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-21 08:11

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表