468,759 Members | 2,056 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,759 developers. It's quick & easy.

converting std::string to std::wstring

I have a an app that I'm writing which uses char and std::string. I'm using
a library which expects wchar_t arrays.

Is there a standard way to convert between std::string and std::wstring, or do
I need to use something like std::transform()?

Thanks

Jul 19 '05 #1
1 11779

"red floyd" <no*****@here.dude> wrote in message news:I3***************@newssvr29.news.prodigy.com. ..
I have a an app that I'm writing which uses char and std::string. I'm using
a library which expects wchar_t arrays.

Is there a standard way to convert between std::string and std::wstring, or do
I need to use something like std::transform()?

Well, there's no real PORTABLE way... it might not even be possible. The whole
concept of the mapping between mb to wc characters is highly implemetnation
dependent. C++ is rather schizoid about whether it's multibyte or wide character
based having a complete implementation of neither.

The best bet is the codecvt C++ class or the mbtowc family of functions in the
C library. All of these work on arrays of characters and not strings, you could
use transform to warp calls to these, but there's no canned function that
does what you want I suspect.

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Flzw | last post: by
3 posts views Thread by Lars Nielsen | last post: by
9 posts views Thread by vsgdp | last post: by
5 posts views Thread by Karthik | last post: by
37 posts views Thread by jortizclaver | last post: by
3 posts views Thread by Angus | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.