C++ 中的可移植 wchar_t [英] Portable wchar_t in C++
问题描述
C++ 中有可移植的 wchar_t 吗?在 Windows 上,它是 2 个字节.其他的都是 4 个字节.我想在我的应用程序中使用 wstring,但如果我决定直接移植它,这会导致问题.
Is there a portable wchar_t in C++? On Windows, its 2 bytes. On everything else is 4 bytes. I would like to use wstring in my application, but this will cause problems if I decide down the line to port it.
推荐答案
如果您正在处理程序内部的使用,请不要担心;A 类中的 wchar_t 与 B 类中的相同.
If you're dealing with use internal to the program, don't worry about it; a wchar_t in class A is the same as in class B.
如果您计划在 Windows 和 Linux/MacOSX 版本之间传输数据,那么您需要担心的不仅仅是 wchar_t,而且您需要想出处理所有细节的方法.
If you're planning to transfer data between Windows and Linux/MacOSX versions, you've got more than wchar_t to worry about, and you need to come up with means to handle all the details.
您可以定义一个类型,您将在任何地方定义为四个字节,并实现您自己的字符串等(因为 C++ 中的大多数文本处理都是模板化的),但我不知道这对它的效果如何您的需求.
You could define a type that you'll define to be four bytes everywhere, and implement your own strings, etc. (since most text handling in C++ is templated), but I don't know how well that would work for your needs.
类似于 typedef int my_char;typedef std::basic_string<my_char>my_string;
这篇关于C++ 中的可移植 wchar_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!