I need to convert std::string to std::wstring. I have used something on below lines with visual studio 2010 (and it's working fine) :-
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; std::string narrow = converter.to_bytes(wide_utf16_source_string); std::wstring wide = converter.from_bytes(narrow_utf8_source_string); However, when I build it on gcc 4.3.4, it gives error :-
.cxx:333: error: 'wstring_convert' is not a member of 'std' .cxx:333: error: 'codecvt_utf8_utf16' is not a member of 'std' Can anyone please provide me some way to do this conversion in platform independent way.
std::wstringisstd::basic_string< wchar_t >, andwchar_titself is not portably defined (16 bits on Windows, 32 bits basically everywhere else), I'd say you should rather be looking atstd::u16string, which is portably defined, including the encoding used... or, even better, use ICU because evenu16stringisn't perfect.<codecvt>.