Hacker News new | ask | show | jobs
by chirsz 72 days ago
It's best to avoid using std::wstring and other wchar_t-related facilities, as they are highly non-portable across different platforms. If you need to interact with the Win32 API, use char16_t and std::u16string, so that anyone knows it contains a UTF-16 encoded string and knows how to use and process it.
1 comments

The Windows API uses WCHAR = wchar_t, so if you use char16_t, you have to convert back and forth to avoid running afoul of strict aliasing rules. This imposes conversion costs without benefits; both using wchar_t directly or converting to/from UTF-8 are better.
Or, set up the manifest in your app[1], and just use UTF-8 and `std::string`/`std::string_view` everywhere.

[1]: https://learn.microsoft.com/en-gb/windows/apps/design/global...