VS2010中Cocos2d-x中文乱码问题
不罗嗦,直接进入主题,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.
所以微软也没打算解决这个问题。
使用其他的编译器是否会有这个问题。但是最好的解决方案还是将文字全部都放到外部资源文件中,然后提供一套文本资源获取的接口。
最新文章
- 【原】安装Win7和Ubuntu双系统后,Win7耳机无声音的解决办法
- ORACLE RAC 11G 更改 /etc/hosts文件
- wcf第2步之服务端标准配置文件
- Angularjs 中使用指令绑定点击事件
- 自定义Angular指令与jQuery实现的Bootstrap风格数据双向绑定的单选&;多选下拉框
- Mac上安装Appium简介
- c# 获取TFS结构 文件
- IDEA无法创建类,接口
- 如何在 Linux 中查找最大的 10 个文件
- rxjs简单入门
- 深入理解arguments.callee
- 【PyQt5-Qt Designer】QLineEdit 文本输入
- Oracle 11.2.0.4下载地址
- eclipse开发mapreduce程序时出现的问题
- mysql存储过程----临时表 temporary
- 开启Apache Server Status
- 两类for循环
- js获取dom元素的子元素,父元素,兄弟元素小记
- 剑指Offer——整数中1出现的次数(从1到n整数中1出现的次数)
- [转]Entity Framework Sprocs with Multiple Result Sets
热门文章
- VS2010-MFC(字体和文本输出:文本输出)
- VS2010-MFC(对话框:属性页对话框及相关类的介绍)
- Keras+Yolo 目标检测
- 简单总结Class.forName("").newinstance()和new()以及classLoader.loadClass("")的区别
- AutoMapper Profile用法
- JS 二维数组
- PAT甲级——A1107 Social Clusters
- spring boot过滤器FilterRegistrationBean
- POJ 2074 /// 判断直线与线段相交 视野盲区
- Java SE开发系列-JDK下载安装