开发者

Convert wchar_t to string?

开发者 https://www.devze.com 2023-03-08 12:59 出处:网络
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).a

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 som开发者_如何学Pythonething really simple.

Thanks in advance!


If you do actually need a string from a wchar_t* then you will first need to convert the wchar_t* to a char*. There are various methods to do this depending on what compiler you are using. The simplest way is to use wcstombs() 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 with wchar_t* as @Space_C0wb0y has mentioned. If that is what you are looking for please mark his answer as correct.

0

精彩评论

暂无评论...
验证码 换一张
取 消