Switching from std::string to std::wstring for embedded applications?

后端 未结 3 497
情书的邮戳
情书的邮戳 2021-01-03 07:11

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

For the next project, I am considering t

相关标签:
3条回答
  • 2021-01-03 07:55

    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.

    UTF-8 encoding is useful when you need to have an 8-bit representation of Unicode characters. (See 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.

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

    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.

    0 讨论(0)
  • 2021-01-03 07:58

    You might get some headache because of the fact that the C++ standard dictates that wide-streams are required to convert double-byte characters to single-byte when writing to a file, and how this conversion is done is implementation-dependent.

    0 讨论(0)
  • 2021-01-03 08:01

    std::wstring is a good choice for holding Unicode strings on Windows, but not on most other platforms, and ceirtanly not for a portable code. Better try to stick with std::string and UTF-8.

    0 讨论(0)
提交回复
热议问题