Click here to Skip to main content
15,886,137 members
Articles / Programming Languages / C++

ASCII strings to Unicode in C++

Rate me:
Please Sign up or sign in to vote.
4.89/5 (2 votes)
28 Mar 2011CPOL 27K   4  
std::string source = "Hello World";std::wstring result( source.begin(), source.end() );One coding line less !

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
13 May 2011blytle
also since _bstr_t's have operator (char *) and operator (wchar_t *) if you have included comutil.h, you can use it to do your conversion.char * source = "this is my source" ;_bstr_t converter_temp(source) ;wstring target ;target = wstring(converter_temp) ;... and the other way...
Please Sign up or sign in to vote.
14 May 2011Philippe Mori
inline std::wstring AsciiToUnicode(std::string text){ // Could do some DEBUG check here to ensure it is really ASCII. // Also, if in the future, it is found, it is not the case, // it would much easier to update code. // Same as jean Davy here... return...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
France France
I'm an independent Software Developer living in the Alpes Maritimes (aka French Riviera).

Even if in the past I have worked regularily with Fortran, Pascal, Basic (not necessarily Visual), and much more esoteric languages (who knows Prolog, Lotus 123 macros ?), even if I still work from time to time with C#, Java or some "interpreted languages", I'm more specialized in C++.
I work on MFC since the very first version, I enjoy working on Visual Studio 2010, its C++0x features, STL, MFC, boost, WTL ...

Comments and Discussions