在C ++中何时使用WCHAR和何时使用CHAR [英] In C++ when to use WCHAR and when to use CHAR

查看:159
本文介绍了在C ++中何时使用WCHAR和何时使用CHAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题:



一些库使用WCHAR作为文本参数,其他库使用CHAR(UTF-8):我需要知道什么时候使用WCHAR

使用 char 和将其视为UTF-8。这有很多原因;这个网站比我可以更好地总结:



http://utf8everywhere.org/



建议将 wchar_t 转换为 char (UTF-16到UTF-8),一旦你从任何库收到它,并转换回当你需要传递字符串到它。所以要回答你的问题,总是使用 char ,除非API要求你传递或接收 wchar_t


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 library.

解决方案

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.

这篇关于在C ++中何时使用WCHAR和何时使用CHAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆