Under Visual Studio source-code-defined strings like L"abc"
result into a C-string with 2-bytes wide chars.
在Visual Studio下,源代码定义的字符串如L“abc”导致带有2字节宽字符的C字符串。
- What about Linux compilers ? Is it also possible to use the L"" syntax ?
- If yes, are the chars of the C-string linux wide chars (i.e 4-bytes wide) ?
- Is there a "cross-compiler" way to define UCS-2 or UTF-16 encoded unicode strings ?
那么Linux编译器呢?是否也可以使用L“”语法?
如果是,是C字符串linux宽字符的字符(即4字节宽)?
是否有“交叉编译”方式来定义UCS-2或UTF-16编码的unicode字符串?
Thank you. :)
谢谢。 :)
EDIT : Forgot to mention that I can't use C++11.
编辑:忘记提到我不能使用C ++ 11。
1 个解决方案
#1
There is no cross-platform way to conveniently write UTF-16 string literals without using at least C11 or C++11 (where you can use u"..."
).
没有至少使用C11或C ++ 11(你可以使用你的“......”),没有跨平台的方法可以方便地编写UTF-16字符串文字。
The wide string syntax (L"..."
) creates a const wchar_t*
using an implementation-defined encoding. On Windows, this encoding is UTF-16; with GCC (using GNU's libc), this encoding is UTF-32.
宽字符串语法(L“...”)使用实现定义的编码创建const wchar_t *。在Windows上,此编码为UTF-16;使用GCC(使用GNU的libc),此编码为UTF-32。
The only safe and portable way to create UTF-16—or any UTF—strings (pre-C11/C++11) is to write them as integer arrays. For example:
创建UTF-16或任何UTF字符串(前C11 / C ++ 11)的唯一安全且可移植的方法是将它们写为整数数组。例如:
const uint16_t str[] = { 0x24EA, 0x0 };
#1
There is no cross-platform way to conveniently write UTF-16 string literals without using at least C11 or C++11 (where you can use u"..."
).
没有至少使用C11或C ++ 11(你可以使用你的“......”),没有跨平台的方法可以方便地编写UTF-16字符串文字。
The wide string syntax (L"..."
) creates a const wchar_t*
using an implementation-defined encoding. On Windows, this encoding is UTF-16; with GCC (using GNU's libc), this encoding is UTF-32.
宽字符串语法(L“...”)使用实现定义的编码创建const wchar_t *。在Windows上,此编码为UTF-16;使用GCC(使用GNU的libc),此编码为UTF-32。
The only safe and portable way to create UTF-16—or any UTF—strings (pre-C11/C++11) is to write them as integer arrays. For example:
创建UTF-16或任何UTF字符串(前C11 / C ++ 11)的唯一安全且可移植的方法是将它们写为整数数组。例如:
const uint16_t str[] = { 0x24EA, 0x0 };