The C++ language standard has no notion of explicit encodings. It only contains an opaque notion of a "system encoding", for which wchar_t
is a "sufficiently large" type.
To convert from the opaque system encoding to an explicit external encoding, you must use an external library. The library of choice would be iconv()
(from WCHAR_T
to UTF-8
), which is part of Posix and available on many platforms, although on Windows the WideCharToMultibyte
functions is guaranteed to produce UTF8.
C++11 adds new UTF8 literals in the form of std::string s = u8"Hello World: \U0010FFFF";
. Those are already in UTF8, but they cannot interface with the opaque wstring
other than through the way I described.
See this question for a bit more background.