微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

了解将使用哪个swprintf或再次将char *string转换为wchar_t *

我试图将一个char *string转换为wchar_t *。 我已经看到这个问题已经被问了很多次,没有解决/便携式答案/解决scheme。

正如这里所build议的,swprintf对我来说似乎是正确的解决scheme,但我发现有两个版本! 即:

http://www.cplusplus.com/reference/cwchar/swprintf/ (第二个参数是string容量)

http://msdn.microsoft.com/en-us/library/ybk95axf%28v=vs.71%29.aspx (第二个参数已经是格式string)

我的程序看起来像这样:

const unsigned int LOCAL_SIZE = 256; char* myCharString = "Hello World!"; wchar_t myWCharString[LOCAL_SIZE];

在这一点上:

Erlang:无法find指定的模块

在Windows和Linux上使用“r +”打开

在Wix中,如何避免在部署registry项时在目标系统上创build物理文件夹?

Linux:是否有可能在进程之间共享代码

SetwindowsHookEx WH_KEYBOARD_LL没有响应右移

swprintf(myWCharString,LOCAL_SIZE,L"%hs",myCharString );

要么:

swprintf(myWCharString,myCharString );

和切换编译器(mingw 4.5.2 < – > mingw 4.7.2)我确实得到了不同的版本,所以在编译的时候有一个错误! 我的问题:

有没有办法知道在编译时我必须select哪两个接口?

有没有一种替代, 便携的方式来转换char *string在wchar_t *? 例如,如果有必要,我可以通过C ++ std库(无C ++ 11)

编辑

std::wstring_convert似乎不适用于我的编译器(4.5.2和4.7.2,包括#include <locale>

我会稍后检查,如果我可以使用Boost格式库来尝试解决这个…

为什么DWORD值通常以hex表示?

如何在Linux中为Qt应用程序制作控制台cmd?

Linux上C的networking摄像头库?

如何在C中更改/显示权限

为什么获得的MachineGuid看起来不像一个GUID,但像韩国人?

由于我可以使用C ++,效率不是问题,所以我可以使用下面的代码

std::wstring(myCharString,myCharString+strlen(myCharString)).c_str()

如果加入wchar_t*是必要的,可能是这样的:

strcpy(myWCharString,std::wstring(myCharString,myCharString+strlen(myCharString)).c_str() );

在这里测试

来自basic_string构造函数方法的文档:

first,last Input iterators to the initial and final positions in a range. The range used is [first,last),which includes all the characters between first and last,including the character pointed by first but not the character pointed by last. The function template argument InputIterator shall be an input iterator type that points to elements of a type convertible to charT. If InputIterator is an integral type,the arguments are casted to the proper types so that signature (5) is used instead.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐