从std :: string切换到std :: wstring的嵌入式应用程序? [英] Switching from std::string to std::wstring for embedded applications?

查看:131
本文介绍了从std :: string切换到std :: wstring的嵌入式应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我在嵌入式系统(路由器,交换机,电话齿轮等)的C ++应用程序中使用std :: string。

Up until now I have been using std::string in my C++ applications for embedded system (routers, switches, telco gear, etc.).

下一个项目,我正在考虑从std :: string切换到std :: wstring的Unicode支持。例如,这将允许最终用户在命令行界面(CLI)中使用中文字符。

For the next project, I am considering to switch from std::string to std::wstring for Unicode support. This would, for example, allow end-users to use Chinese characters in the command line interface (CLI).

我应该期望什么复杂化/头痛/惊喜?例如,如果我使用仍然使用std :: string的第三方库?

What complications / headaches / surprises should I expect? What, for example, if I use a third-party library which still uses std::string?

因为支持国际字符串不是强大的要求

Since support for international strings isn't that strong of a requirement for the type of embedded systems that I work on, I would only do it if it isn't going to cause major headaches.

推荐答案

注意,许多通信协议需要8位字符(或7位字符或其他变体),因此您通常需要在内部wchar_t / wstring数据和外部编码之间进行转换。

Note that many communications protocols require 8-bit characters (or 7-bit characters, or other varieties), so you will often need to translate between your internal wchar_t/wstring data and external encodings.

当您需要具有Unicode字符的8位表示形式时,UTF-8编码很有用。 (请参见 http://stackoverflow.com/问题/ 134371 / how-do-you-write-code-that-is-is-safe-for-utf-8 了解更多信息。)但是请注意,您可能需要支持其他编码。

UTF-8 encoding is useful when you need to have an 8-bit representation of Unicode characters. (See http://stackoverflow.com/questions/134371/how-do-you-write-code-that-is-safe-for-utf-8 for some more info.) But note that you may need to support other encodings.

越来越多的第三方库支持Unicode,但仍然有许多不支持Unicode。

More and more third-party libraries are supporting Unicode, but there are still plenty that don't.

真的告诉你是否值得头痛。这取决于你的要求。如果你从头开始,那么从std :: wstring开始比从std :: string到std :: wstring稍后更容易。

I can't really tell you whether it is worth the headaches. It depends on what your requirements are. If you are starting from scratch, then it will be easier to start with std::wstring than converting from std::string to std::wstring later.

这篇关于从std :: string切换到std :: wstring的嵌入式应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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