In C++ when to use WCHAR and when to use CHAR

前端 未结 5 1676
春和景丽
春和景丽 2020-12-14 03:56

I have a question:

Some libraries use WCHAR as the text parameter and others use CHAR (as UTF-8): I need to know when to use WCHAR or CHAR when I write my own librar

5条回答
  •  清歌不尽
    2020-12-14 04:11

    Use char and treat it as UTF-8. There are a great many reasons for this; this website summarises it much better than I can:

    http://utf8everywhere.org/

    It recommends converting from wchar_t to char (UTF-16 to UTF-8) as soon as you receive it from any library, and converting back when you need to pass strings to it. So to answer your question, always use char except at the point that an API requires you to pass or receive wchar_t.

提交回复
热议问题