Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Linux equivalent of: MultiByteToWideChar & WideCharToMultiByte?

I am working with a class that wraps the std::wstring, this code needs to be cross platform, are there equivalents to the windows functions: MultiByteToWideChar & WideCharToMultiByte on linux?

Thank you.

like image 450
NSA Avatar asked Jul 18 '10 19:07

NSA


2 Answers

The Linux equivalents are the iconv functions iconv_open, iconv and iconv_close (say man 3 iconv_open etc. for the documentation). For cross-platform applications, use dedicated libraries such as ICU instead. Such libraries already contain their own string classes; there is no need to wrap std::wstring.

like image 76
Philipp Avatar answered Sep 16 '22 21:09

Philipp


mbtowc and wctomb are the most direct equivalents, but note that they operate on the multibyte character set corresponding to the current LC_CTYPE locale (which can be changed with setlocale()).

like image 43
caf Avatar answered Sep 19 '22 21:09

caf