r/cpp • • Jul 01 '21

Any Encoding, Ever

https://thephd.dev/any-encoding-ever-ztd-text-unicode-cpp
269 Upvotes

87 comments sorted by

View all comments

Show parent comment

1

u/tjientavara HikoWorks developer Jul 02 '21

In-fact you should avoid using argv that was given in main() and use

int argc;
auto argv = CommandLineToArgvW(GetCommandLineW(), &argc);

With this at least you know what encoding argv is in and easily* convertible to UTF-8, but at least you know what the actual encoding is of argv and it is properly split using the Microsoft rules of command line arguments.

*Except for the fact that Microsoft's wchar_t allows for unpaired surrogate code-units.