string与wstring转换
来源:互联网 发布:淘宝瓜子是什么类目 编辑:程序博客网 时间:2024/05/16 08:54
转自:http://www.cnblogs.com/02xiaoma/archive/2012/07/18/2597576.html
- 方法一:MultiByteToWideChar、WideCharToMultiByte
1 BOOL StringToWString(const std::string &str,std::wstring &wstr) 2 { 3 int nLen = (int)str.length(); 4 wstr.resize(nLen,L' '); 5 6 int nResult = MultiByteToWideChar(CP_ACP,0,(LPCSTR)str.c_str(),nLen,(LPWSTR)wstr.c_str(),nLen); 7 8 if (nResult == 0) 9 {10 return FALSE;11 }12 13 return TRUE;14 }15 //wstring高字节不为0,返回FALSE16 BOOL WStringToString(const std::wstring &wstr,std::string &str)17 { 18 int nLen = (int)wstr.length(); 19 str.resize(nLen,' ');20 21 int nResult = WideCharToMultiByte(CP_ACP,0,(LPCWSTR)wstr.c_str(),nLen,(LPSTR)str.c_str(),nLen,NULL,NULL);22 23 if (nResult == 0)24 {25 return FALSE;26 }27 28 return TRUE;29 }
- 方法二:std::copy
1 std::wstring StringToWString(const std::string &str) 2 { 3 std::wstring wstr(str.length(),L' '); 4 std::copy(str.begin(), str.end(), wstr.begin()); 5 return wstr; 6 } 7 8 //只拷贝低字节至string中 9 std::string WStringToString(const std::wstring &wstr)10 {11 std::string str(wstr.length(), ' ');12 std::copy(wstr.begin(), wstr.end(), str.begin());13 return str; 14 }
0 0
- string与wstring转换
- string与wstring转换
- string与wstring转换
- string与wstring转换
- string与wstring转换
- string与wstring转换
- string与wstring转换
- string与wstring转换
- wstring 与 string 的转换
- wstring与string相互转换
- wstring与string相互转换
- wstring 与 string 之间的转换
- string与wstring的相互转换
- 关于string与wstring之间的转换
- std::wstring 与std::string 转换
- STL中string与wstring的转换
- string wstring 转换
- string 与wstring
- 从零开始学新浪微博分享和第三方登陆(附源码下载)
- 无缝幻灯片2
- ACM——01——1001: 【入门】A+B Problem 熟悉一下Online Judge的环境
- 指针在数组中的数据传递作用
- 欧拉计划---0003 Largest prime factor(找出一个合数的最大质数因子)
- string与wstring转换
- poj2139
- c++中冒号(:)和双冒号(::)的用法
- 黑马程序员------C语言-----结构体和枚举
- **Codeforces Round #250 (Div. 2) C. The Child and Toy ACM解题报告(贪心难题)
- 我是如何找实习 (or 工作)的
- UISegmentedControl的总结还不错!
- 极光推送使用实例(二) Android客户端
- 图的拓扑排序