What is the difference between WideCharToMultiByte() and wcstombs() When to use which one?
In a nutshell: the WideCharToMultiByte
function exposes the encodings/code pages used for the conversion in the parameter list, while wcstombs
does not. This is a major PITA, as the standard does not define what encoding is to be used to produce the wchar_t
, while you as a developer certainly need to know what encoding you are converting to/from.
Apart from that, WideCharToMultiByte
is of course a Windows API function and is not available on any other platform.
Therefore I would suggest using WideCharToMultiByte
without a moment's thought if your application is not specifically written to be portable to non-Windows OSes. Otherwise, you might want to wrestle with wcstombs
or (preferably IMHO) look into using a full-feature portable Unicode library such as ICU.