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_ ...
随机推荐
- C语言学习second--C语言基础学习
1.标准C语言 C语言诞生于20世纪70年代,年龄比我们自己还要大,期间产生了很多标准,但是各种编译器对标准的支持不尽相同. ANSI C是使用的最广泛的一个标准,也是第一个正式标准,被称为“标准C语 ...
- SQL Server 内存管理在64位时代的改变
64位机上 地址空间比以前大了去了.它引起的改变多了去了 1.MemToLeave这个词不存在了.因为SQL Server以不再做这种预留空间的事了,也就是说multiple page 想用多少就用 ...
- C++类对应的内存结构
提示1:对“内存结构”表示有疑问或不解的,先参考: http://blog.csdn.net/guogangj/archive/2007/05/25/1625199.aspx, 本文使用的表示方法和V ...
- hdu 1575 Tr A(矩阵快速幂乘法优化算法)
Problem Description A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%. Input 数据的第一行是一个T,表示有T组数据. 每组数据的第一行有n ...
- VS2010中更改项目名称(转载)
一.修改解决方案的名称:直接选择解决方案,右键重命名即可.
- 【LeetCode】【Python】Linked List Cycle
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using ex ...
- DSOframer 无法正常加载的解决方案
不了解 DSOframer 的朋友,可以先参考文章 DSOframer 的简单介绍和资源整理. 在使用 DSOframer 时,经常会碰到各种奇奇怪怪的问题,最常见的就是控件不能正常加载.大家可以按下 ...
- 前端开发必备的Sublime 3插件
Sublime的大名已经无需我介绍了,首先先介绍如何启用插件安装功能: 打开Sublime 3,然后按 ctrl+` 或者在View → Show Console 在打开的窗口里黏贴这个网站上的代码( ...
- jQuery关于mouseover和mouseenter的区别
原生的mouseenter是dom3级的事件,对于jQuery等一些框架已经实现了这个事件.但是它到底跟mouseover有什么区别? jQuery在实现这两个事件的时候,mouseover支持事件冒 ...
- Java Math的 floor,round和ceil的总结
floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下 ...