博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cocos2d-x中中文显示问题解决方法二
阅读量:2304 次
发布时间:2019-05-09

本文共 1279 字,大约阅读时间需要 4 分钟。

原创作品,允许转载,转载时请务必以超链接形式标明文章 、作者信息和本声明。否则将追究法律责任。

 

中文显示问题方法二(通过转码来使中文显示)

 

------------------------------------------相关代码--------------------------------------

(1)Tools.h

#ifndef _TOOLS_H_#define  _TOOLS_H_//中文转码#include "cocos2d.h"#pragma comment(lib, "libiconv.lib")int GBKToUTF8(std::string & gbkStr, const char* toCode, const char* fromCode);#endif

(2)Tools.cpp

#include "Tools.h"#include "iconv\iconv.h"int GBKToUTF8(std::string & gbkStr, const char* toCode, const char* fromCode){	iconv_t iconvH;	iconvH = iconv_open(fromCode, toCode);	if (iconvH == 0)	{		return -1;	}	const char* strChar = gbkStr.c_str();	const char** pin = &strChar;	size_t strLength = gbkStr.length();	char* outbuf = (char*) malloc(strLength*4);	char* pBuff = outbuf;	memset( outbuf, 0, strLength*4);	size_t outLength = strLength*4;	if (-1 == iconv(iconvH, pin, &strLength, &outbuf, &outLength))	{		iconv_close(iconvH);		return -1;	}	gbkStr = pBuff;	iconv_close(iconvH);	return 0;}
 

(3)调用界面(含要包含的头文件)

#include "iconv\iconv.h"#include "Tools.h"//通过转码显示中文std::string china="用户名:";GBKToUTF8(china,"gbk","utf-8");CCLabelTTF* pLabel2 = CCLabelTTF::create(china.c_str(), "Marker Felt", 24);pLabel2->setPosition(ccp(300, 500));this->addChild(pLabel2, 2);
 
----------------------相关代码-------------------------------
你可能感兴趣的文章
nginx负载均衡配置及测试
查看>>
Git-2.17.0推送整个工程到Github
查看>>
Mybatisz之SQL片段(21)
查看>>
关于在ubuntu平台下使用apt-get命令下载速度太慢的问题解决
查看>>
MongoDB使用Java操作数据库案例
查看>>
反射之Constructor类
查看>>
Ubuntu Linux 13.10 中WPS输入法无法跟随显示问题
查看>>
Linux平台超级好用服务器远程管理工具webmin的安裝
查看>>
CentOS 5.2 下用Yum安装Apache+PHP+MySQL环境
查看>>
Linux操作系统下挂载远程Windows共享目录
查看>>
apache+php+mysql安装配置
查看>>
Ubuntu下pythn+Django+mysql配置
查看>>
Sublime text 3 安装pylinter的错误提示
查看>>
去掉Sublime Text 3烦人的更新新版本提醒
查看>>
启动vsftpd的问题---500 OOPS
查看>>
Linux下安装FTP服务器--vsftpd
查看>>
去掉excel保存文件时提示:隐私问题警告:此文档中包含宏
查看>>
ShellExecute详解
查看>>
sqlite3支持自增和缺省值列
查看>>
android handle thread runnable的关系
查看>>