cocos2dx在写中文字体的时候出现乱码
发布时间:2020-12-14 21:23:19 所属栏目:百科 来源:网络整理
导读:有时候,根据程序的需要,可能会添加中文字体,但是程序在编码的时候可以能会出现乱码,那么这么处理呢,看如下代码: #include stdio.h#include stdlib.h#include string.h#ifdef WIN32#define UTEXT(str) GBKToUTF8(str)#else#define UTEXT(str) str#endif
有时候,根据程序的需要,可能会添加中文字体,但是程序在编码的时候可以能会出现乱码,那么这么处理呢,看如下代码: #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef WIN32 #define UTEXT(str) GBKToUTF8(str) #else #define UTEXT(str) str #endif #ifdef WIN32 #include "platform/third_party/win32/iconv/iconv.h" static char g_GBKConvUTF8Buf[5000] = {0}; const char* GBKToUTF8(const char *strChar) { iconv_t iconvH; iconvH = iconv_open("utf-8","gb2312"); if (iconvH == 0) { return NULL; } size_t strLength = strlen(strChar); size_t outLength = strLength<<2; size_t copyLength = outLength; memset(g_GBKConvUTF8Buf,5000); char* outbuf = (char*) malloc(outLength); char* pBuff = outbuf; memset( outbuf,outLength); if (-1 == iconv(iconvH,&strChar,&strLength,&outbuf,&outLength)) { iconv_close(iconvH); return NULL; } memcpy(g_GBKConvUTF8Buf,pBuff,copyLength); free(pBuff); iconv_close(iconvH); return g_GBKConvUTF8Buf; } #endif 上面是汉字转换,有可能出先连接出问题的情况,那是程序所用到的iconv的lib没用添加进去,你只需要在你的工程--属性--连接--输入--添加依赖项--libiconv.lib(添加这个lib文件就可以了) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Flex样式-MenuBar篇
- c# – 使用WCF在两个winform应用程序之间进行通信?
- Flash builder发布Air程序时设备配置文件supportedProfiles
- c – std :: array的部分模板参数推导或解决方法?
- c# – 仅将方面应用于具有特定属性的方法
- 基于cocos2dx的RPG简单实用算法之3 - 多角色跟随阵型移动
- ruby-on-rails – Rails:find_by_sql和虚拟列
- Swift语言中某个财产的感叹号是什么?
- lazarus中建立空sqlite数据库
- 什么是swift 3中的NSTimer.scheduledTimerWithTimeInterval