How to convert string to wstring?
How to convert string to wstring? - Codejie's C++ Space - C++博客
How to convert string to wstring?
来源:http://www.codeguru.com/forum/archive/index.php/t-193852.htmlThe copy() function does not automatically make room for the destination, so you must make sure that you have enough room in the wstring.
Why not just write a function to do the conversion?
#include <string>
#include <algorithm>// Prototype for conversion functions
std::wstring StringToWString(const std::string& s);
std::string WStringToString(const std::wstring& s);std::wstring StringToWString(const std::string& s)
{
std::wstring temp(s.length(),L' ');
std::copy(s.begin(), s.end(), temp.begin());
return temp;
}std::string WStringToString(const std::wstring& s)
{
std::string temp(s.length(), ' ');
std::copy(s.begin(), s.end(), temp.begin());
return temp;
}using namespace std;
int main()
{
string s1 = "Hello";
wstring s2 = StringToWString(s1);
s1 = WStringToString(s2);
return 0;
}Regards,
Paul McKenzie
posted on 2009-03-27 12:35 codejie 阅读(655) 评论(6) 编辑 收藏 引用 所属分类: Resource
评论
# re: How to convert string to wstring? 2009-03-27 13:03 陈梓瀚(vczh)你试试汉字。 回复 更多评论
# re: How to convert string to wstring? 2009-03-27 17:56 codejie么问题。 回复 更多评论
# re: How to convert string to wstring? 2009-03-27 22:59 陈梓瀚(vczh)你如何判断他没事 回复 更多评论
# re: How to convert string to wstring?[未登录] 2009-03-29 23:03 codejie可以正常读取一个中文文件名的MP3文件。你有什么疑问吗? 回复 更多评论
# re: How to convert string to wstring?[未登录] 2013-11-26 01:19 烟圈int main()
{
//string s1 = "";
//wstring s2 = StringToWString(s1);
string s1 = WStringToString(L"中国");cout <<s1 <<endl;
return 0;
}试试肯定不行。。
How to convert string to wstring?的更多相关文章
- 基于标准库实现string和wstring的转换
// convert string to wstring std::wstring to_wstring(const std::string& str, const std::locale&a ...
- string、wstring、cstring、 char、 tchar、int、dword转换方法(转)
string.wstring.cstring. char. tchar.int.dword转换方法(转) 最近编程一直头痛这集中类型的转化,明知都可以转却总是记不住,不断的上网查来查去,在这里小结 ...
- svn: Can't convert string from 'UTF-8' to native encoding 的解决办法(转)
http://www.cnblogs.com/xuxm2007/archive/2010/10/26/1861223.html svn 版本库中有文件是以中文字符命名的,在 Linux 下 check ...
- STL的string和wstring
STL有字符串处理类——stirng和wstring,但是用的时候会觉得不是很方便,因为它不能像TCHAR一样根据定义的宏在char类型字符串和wchar_t进行转换,总不能因为程序要Unicode就 ...
- 【转载】解决 Subversion 的 “svn: Can't convert string from 'UTF-8' to native encoding” 错误
转载自:http://blog.csdn.net/shaohui/article/details/3996274 在google code 上创建了一个新的项目, 用Windows 下面的tortoi ...
- [C++]C++标准里 string和wstring
typedef basic_string<char> string; typedef basic_string<wchar_t> wstring; 前者string是常用类型, ...
- svn: Can't convert string from 'UTF-8' to native encoding 的解决办法
http://www.leakon.com/archives/610 http://www.toplee.com/blog/566.html http://svnbook.red-bean.com/e ...
- 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换 [转]
本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下. #ifndef USE_H_ #define USE_H_ # ...
- 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换
本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下-复制代码 代码如下: #ifndef USE_H_ ...
随机推荐
- Oracle EBS-SQL (INV-9):检查搬运单分配异常.sql
select h.request_number, l.line_number, msib.segment1 item_code, t.transacti ...
- 组队练习赛(Regionals 2012, North America - East Central NA)
A.Babs' Box Boutique 给定n个盒子,每个盒子都有长宽高(任意两个盒子长宽高不完全相同),现在选盒子的任意两面,要求x1 <= x2 && y1 <= y ...
- android开发的问题集(二)
(1)子线程对UI线程操作的简便方法 子线程方法用 Looper.prepare(); 结束时候用 Looper.loop();
- WIN_2003_SP2.iso VMware 不能进行网络访问的处理
1.打开IE发现不能上网的问题 ping命令 发现确实是网络不通: 2.关闭虚拟机设置网络适配器 3.ping命令验证是否设置成功 4.打开IE访问百度
- poj 2425 A Chess Game_sg函数
题意:给你一个有向无环图,再给你图上的棋子,每人每次只能移动一个棋子,当轮到你不能移动棋子是就输了,棋子可以同时在一个点 比赛时就差这题没ak,做了几天博弈终于搞懂了. #include <io ...
- 无限递归的构造器和javap使用指南
无限递归的构造器和javap使用指南 public class ConstructorRecursion { ConstructorRecursion rc; { rc = newConstructo ...
- STL map+vector+struct的使用示例
个人编写的小例子,没有注释,刚毕业时作为技术调研随手编写,仅供参考: #include<iostream> #include<map> #include<vector&g ...
- Search gold(dp)
Search gold Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Subm ...
- leetcode_question_130 Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...
- UVA 1615 Highway
题意: 有一条沿x轴正方向,长为L的高速公路,n个村庄,要求修建最少的公路出口数目,使得每个村庄到出口的距离不大于D. 分析: 每个村子可建出口的距离是(l-d,r+d).将所有区间按右端点排序,若需 ...