不罗嗦,直接进入主题,VS2010的默认编码是"GB2312",那么以创建一个label为例,当我们使用

CCLabelTTF::create(const char *label, const char *fontName, float fontSize)

来创建label的时候,const char* 参数要求是utf-8编码的字符串,如果传入一个非utf-8编码的字符串,那么创建的label显示就会有些不正常。

这是一个编译器相关的问题,和源文件保存的编码没有太大关系。

使用VS C++开发,如果硬要解决这个问题,可以将文件保存为"无签名的UTF-8"编码。

但是在VS C++中使用"无签名的UTF-8"又会带来新的问题

#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
  const char str[] = "退出";
  return ;
}

然后保存为"无签名的UTF-8"并编译

1>: warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
1>: error C2001: 常量中有换行符
1>: error C2143: 语法错误 : 缺少“;”(在“return”的前面)

有人提交过类似的问题,根据微软的解释:

The compiler when faced with a source file that does not have a BOM the compiler reads ahead a certain distance into the file to see if it can detect any Unicode characters - it specifically looks for UTF-16 and UTF-16BE - if it doesn't find either then it assumes that it has MBCS. I suspect that in this case that in this case it falls back to MBCS and this is what is causing the problem.

所以微软也没打算解决这个问题。

使用其他的编译器是否会有这个问题。但是最好的解决方案还是将文字全部都放到外部资源文件中,然后提供一套文本资源获取的接口。

最新文章

  1. 【原】安装Win7和Ubuntu双系统后,Win7耳机无声音的解决办法
  2. ORACLE RAC 11G 更改 /etc/hosts文件
  3. wcf第2步之服务端标准配置文件
  4. Angularjs 中使用指令绑定点击事件
  5. 自定义Angular指令与jQuery实现的Bootstrap风格数据双向绑定的单选&多选下拉框
  6. Mac上安装Appium简介
  7. c# 获取TFS结构 文件
  8. IDEA无法创建类,接口
  9. 如何在 Linux 中查找最大的 10 个文件
  10. rxjs简单入门
  11. 深入理解arguments.callee
  12. 【PyQt5-Qt Designer】QLineEdit 文本输入
  13. Oracle 11.2.0.4下载地址
  14. eclipse开发mapreduce程序时出现的问题
  15. mysql存储过程----临时表 temporary
  16. 开启Apache Server Status
  17. 两类for循环
  18. js获取dom元素的子元素,父元素,兄弟元素小记
  19. 剑指Offer——整数中1出现的次数(从1到n整数中1出现的次数)
  20. [转]Entity Framework Sprocs with Multiple Result Sets

热门文章

  1. VS2010-MFC(字体和文本输出:文本输出)
  2. VS2010-MFC(对话框:属性页对话框及相关类的介绍)
  3. Keras+Yolo 目标检测
  4. 简单总结Class.forName("").newinstance()和new()以及classLoader.loadClass("")的区别
  5. AutoMapper Profile用法
  6. JS 二维数组
  7. PAT甲级——A1107 Social Clusters
  8. spring boot过滤器FilterRegistrationBean
  9. POJ 2074 /// 判断直线与线段相交 视野盲区
  10. Java SE开发系列-JDK下载安装