在C使用统一code ++源文件 [英] Using Unicode in a C++ source file

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

问题描述

我用C ++的资源文件中,我想有一个包含亚洲统一code字带引号的字符串的工作。

I'm working with a C++ sourcefile in which I would like to have a quoted string that contains Asian Unicode characters.

我和QT在Windows上工作,和Qt Creator的开发环境具有显示的统一code没有问题。在将QString也没有问题,统一存储code。当我在统一code粘贴,它显示细腻,是这样的:

I'm working with QT on Windows, and the QT Creator development environment has no problem displaying the Unicode. The QStrings also have no problem storing Unicode. When I paste in my Unicode, it displays fine, something like:

#define MY_STRING 鸟

然而,当我保存,我可爱的统一code人物都变成什么?标记。

However, when I save, my lovely Unicode characters all become ? marks.

我试图打开源文件并重新保存为统一code EN codeD。然后,它显示和Qt Creator中正确保存。然而,在编译,好像编译器不知道该怎么办这个问题,并抛出一吨误导的错误和警告,如流浪\\程序255和忽略空字符(S)。

I tried to open up the source file and resave it as Unicode encoded. It then displays and saves correctly in QT Creator. However, on compile, it seems like the compiler has no idea what to do with this, and throws a ton of misguided errors and warnings, such as "stray \255 in program" and "null character(s) ignored".

什么是包含在中联code正确的做法++源文件?

推荐答案

就个人而言,我不使用源$ C ​​$ C任何非ASCII字符。其原因是,如果你在你的源文件中使用arbitary统一code字符,你不用担心,编译器认为源文件是在编码,有什么执行字符集,它将使用以及它如何会做源到执行字符集转换。

Personally, I don't use any non-ASCII characters in source code. The reason is that if you use arbitary Unicode characters in your source files, you have to worry about the encoding that the compiler considers the source file to be in, what execution character set it will use and how it's going to do the source to execution character set conversion.

我认为这是一个更好的主意,有某种形式的资源文件,它可以在编译时被编译为静态数据或在运行时实现最大的灵活性统一加载code数据。这样,你可以控制编码是如何发生的,在不担心编译器的行为方式可能是通过在编译时局部区域设置的影响。

I think that it's a much better idea to have Unicode data in some sort of resource file, which could be compiled to static data at compile time or loaded at runtime for maximum flexibility. That way you can control how the encoding occurs, at not worry about how the compiler behaves which may be influence by the local locale settings at compile time.

这确实需要多一点的基础设施,但是如果你有国际化这是值得花时间选择或开发一个灵活和强大的战略。

It does require a bit more infrastructure, but if you're having to internationalize it's well worth spending the time choosing or developing a flexible and robust strategy.

虽然可以使用通用字符转义( L'为\\ uXXXX)或明确EN codeD字节序列(\\ XXX \\ XYY \\ XZZ)的源$ C ​​$ C,这使得统一code字符串人类几乎无法读取。如果您遇到的翻译使得它更容易为参与这一进程大多数人能在商定的通用字符编码方案来处理文本。

While it's possible to use universal character escapes (L'\uXXXX') or explicitly encoded byte sequences ("\xXX\xYY\xZZ") in source code, this makes Unicode strings virtually unreadable for humans. If you're having translations made it's easier for most people involved in the process to be able to deal with text in an agreed universal character encoding scheme.

这篇关于在C使用统一code ++源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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