wcstombs documentation says, it “converts the sequence of wide-character codes to multibyte string”. But it never says what is a “wide-character”.
Is it implicit, like say it converts utf-16 to utf-8 or the conversion is defined by some environment variable?
Also what is the typical use case of wcstombs?
You use the
setlocale()standard function with theLC_CTYPE(orLC_ALL) category to set the mapping the library uses betweenwchar_tcharacters and multibyte characters. The actual locale name passed tosetlocale()is implementation defined, so you’ll need to look it up in your compiler’s docs.For example, with MSVC you might use
to set the C runtime to use codepage 1252 as the multibyte character set. Note that MSVC docs explicitly indicates that the locale cannot be set to UTF-7 or UTF8 for the multibyte character sets:
The “wide-character”
wchar_ttype is intended to be able to support any character set the system supports – the standard doesn’t define the size of awchar_ttype (it could be as small as acharor any of the larger integer types). On Windows it’s the system’s ‘internal’ Unicode encoding, which is UTF-16 (UCS-2 before WinXP). Honestly, I can’t find a direct quote on that in the MSVC docs, though. Strictly speaking, the implementation should call this out, but I can’t find it.