将 wchar_t 转换为字符串?
我有一个 wchar_t
我想转换为 string
。然后应该使用 stringstream 读取该字符串。我在这里查看了转换它: http:// msdn.microsoft.com/en-us/library/ms235631(v=vs.80).aspx 但它们都没有返回任何可用于 stringstream
的内容。我对编码不太有经验,所以我可能错过了一些非常简单的东西。
提前致谢!
I have a wchar_t
I'd like to convert to a string
. The string should then be read using stringstream
. I have looked converting it over here: http://msdn.microsoft.com/en-us/library/ms235631(v=vs.80).aspx but none of them return anything useable with stringstream
. I'm not very experienced with coding so I'm probably missing something really simple.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您实际上需要来自
wchar_t*
的字符串
,那么您首先需要将wchar_t*
转换为一个char*
。根据您使用的编译器,有多种方法可以执行此操作。最简单的方法是使用 wcstombs() ,但有一些注意事项。这里有一个关于这个问题的很好的讨论,其中一些解决方案可能会启发您 http:// /www.daniweb.com/software-development/cpp/threads/87362。但是,您可以直接将
wstring
与wchar_t*
一起使用,如 @Space_C0wb0y 所提到的。 如果这就是您正在寻找的内容,请将他的答案标记为正确。If you do actually need a
string
from awchar_t*
then you will first need to convert thewchar_t*
to achar*
. There are various methods to do this depending on what compiler you are using. The simplest way is to usewcstombs()
but there are caveats with that. Here is a good discussion on the matter, with some solutions that might inspire you http://www.daniweb.com/software-development/cpp/threads/87362.However you can just use
wstring
directly withwchar_t*
as @Space_C0wb0y has mentioned. If that is what you are looking for please mark his answer as correct.