string 到 wstring的转换_一景_新浪博客

    string 到 wstring的转换
    (2009-08-10 20:52:34)
    转载▼
    标签:
    杂谈
        分类: CEGUI

    在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;

    }

         好不好谁用谁知道啊!

string 到 wstring的转换的更多相关文章

  1. string 与wstring 的转换

    std::wstring StringToWString(const std::string &str) { std::wstring wstr(str.length(),L' '); std ...

  2. 基于标准库实现string和wstring的转换

    // convert string to wstring std::wstring to_wstring(const std::string& str, const std::locale&a ...

  3. 关于string转换为wstring问题

    方法一:需要调用windows的api函数进行转换,在vs2017上试验转换成功 #ifdef _MSC_VER #include <Windows.h> #endif // _MSC_V ...

  4. 利用boost做string到wstring转换,以及字符集转换 - Error - C++博客

    利用boost做string到wstring转换,以及字符集转换 - Error - C++博客 利用boost做string到wstring转换,以及字符集转换 #include <boost ...

  5. c++ string与wstring转换

    wchar_t to char #include <comdef.h> const wchar_t* exepath = L"d:\\中文 路径\\中文 路径.exe" ...

  6. STL的string和wstring

    STL有字符串处理类——stirng和wstring,但是用的时候会觉得不是很方便,因为它不能像TCHAR一样根据定义的宏在char类型字符串和wchar_t进行转换,总不能因为程序要Unicode就 ...

  7. 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换 [转]

    本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下. #ifndef USE_H_ #define USE_H_ # ...

  8. 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换

    本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下-复制代码 代码如下:    #ifndef USE_H_     ...

  9. string、wstring、cstring、 char、 tchar、int、dword转换方法(转)

    string.wstring.cstring. char. tchar.int.dword转换方法(转)   最近编程一直头痛这集中类型的转化,明知都可以转却总是记不住,不断的上网查来查去,在这里小结 ...

随机推荐

  1. UVA 10375 Choose and divide

    n! 分解素因子 快速幂 ei=[N/pi^1]+ [N/pi^2]+ …… + [N/pi^n]  其中[]为取整 ei 为数 N!中pi 因子的个数: #include <iostream& ...

  2. 14.3.5 LOCK TABLES and UNLOCK TABLES Syntax

    14.3.5 LOCK TABLES and UNLOCK TABLES Syntax LOCK TABLES tbl_name [[AS] alias] lock_type [, tbl_name ...

  3. fstab 介绍

    http://forum.ubuntu.org.cn/viewtopic.php?t=58468 主要翻译自http://www.tuxfiles.org/linuxhelp/fstab.html,根 ...

  4. 二探ListView

    使用draw9patch 打开内置terminal 输入CD C:\Users\Gaby\AppData\Local\Android\sdk 在该目录下输入draw9patch 导入图片,开始绘制 本 ...

  5. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  6. 【LeetCode练习题】Linked List Cycle II

    Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it ...

  7. 安装android studio时,解决unable to access android sdk add-on list

    1.打开时提示如下错误. 2.在安装路径下找到idea.properties文件,用记事本打开,添加disable.android.first.run=true,保存即可. 3.再次打开Android ...

  8. 为下拉式菜单(DropDownList)添加第一个选项

    很多方法可以为为下拉式菜单(DropDownList)添加第一个选项,下面是Insus.NET小结了几个方法,仅供参考: Html code: <body>    <form id= ...

  9. UVA - 10131Is Bigger Smarter?(DAG上的DP)

    题目:UVA - 10131Is Bigger Smarter? (DAG) 题目大意:给出一群大象的体重和IQ.要求挑选最多的大象,组成一个序列.严格的体重递增,IQ递减的序列.输出最多的大象数目和 ...

  10. leetcode_question_102 Binary Tree Level Order Traversal

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...