When I have C++ code like this:
std::string narrow( "This is a narrow source string" );
std::string n2( "Win-1252 (that's the encoding we use for source files): ä,ö,ü,ß,€, ..." );
// What encoding should I pass to Win32's `MultiByteToWideChar` function
// to convert these string to a propoer wchar_t (= UTF-16 on Windows)?
Can I always assume Win-1252 if that's the (implicit) encoding of our cpp files? How does the Visual-C++ compiler decide which character encoding the source files are in?
What would happen if, say, a developer uses a machine where "normal" text files default to another single/multibyte encoding?
I assume the encoding is only an issue on the machine used to compile the code? That is, once the executable is built, converting a static string from a fixed narrow encoding to Windows' UTF-16 wchar_t will always yield the same result regardless of the laguage/locale on the users PC?
std::wstring wide(L"This is a wide source string"); std::wstring w2(L"ä,ö,ü,ß,€, ...");L""equates towchar_t[], andwchar_t-based strings can hold UTF-16 encoded data on Windows. On other platforms, like Linux,wchar_tis UTF-32, so you would have to convert at runtime, such as with iconv. Otherwise, if you need to support multiple platforms, you should use a cross-platform library, like ICU, to work with Unicode strings in a uniform manner.char16_tandu""to force UTF-16 on all platforms,eg:std::basic_string<char16_t> utf16(u"This is a UTF-16 source string");char8_tandu8""for that, otherwise use escape sequences for non-ASCII bytes. Either way, you can then use theCP_UTF8codepage withMultiByteToWideChar()when converting to UTF-16."..."- which encoding will it be?