converting std::string to std::wstring

R

red floyd

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
 
R

Ron Natalie

red floyd said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top