博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CCString
阅读量:4671 次
发布时间:2019-06-09

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

Introduction

CCString is inherited from the CCObject class. CCObject exist primarily as an automatic memory management object. CCString provided a series of interface such as create, convert etc..

Useful Methods

Creation :

1 2    /** create a string with std string, you can also pass a c string pointer because the default constructor of std::string can access a c string pointer.  3 4     * @return A CCString pointer which is an autorelease object pointer, 5 6     * it means that you needn't do a release operation unless you retain it. 7 8     */ 910    static CCString* create(const std::string& str);1112    /** create a string with format, it's similar with the c function 'sprintf', the default buffer size is (1024*100) bytes,1314     * if you want to change it, you should modify the kMaxStringLen macro in CCString.cpp file.1516     * @return A CCString pointer which is an autorelease object pointer,1718     * it means that you needn't do a release operation unless you retain it.1920     */ 2122    static CCString* createWithFormat(const char* format, …);2324    /** create a string with binary data 2526     * @return A CCString pointer which is an autorelease object pointer,2728     * it means that you needn't do a release operation unless you retain it.2930     */3132    static CCString* createWithData(const unsigned char* pData, unsigned long nLen);3334    /** create a string with a file, 3536     * @return A CCString pointer which is an autorelease object pointer,3738     * it means that you needn't do a release operation unless you retain it.3940     */4142    static CCString* createWithContentsOfFile(const char* pszFileName);43

Conversion

The CCString is also allows a CCString variable converts to a variable of another type:

1 2    /** convert to int value */ 3 4    int intValue() const; 5 6    /** convert to unsigned int value */ 7 8    unsigned int uintValue() const; 910    /** convert to float value */1112    float floatValue() const;1314    /** convert to double value */1516    double doubleValue() const;1718    /** convert to bool value */1920    bool boolValue() const;21

Useful Macros

12#define CCStringMake(str) CCString::create(str)34#define ccs CCStringMake5

These macros can construct an autorelease CCString object more easily, e.g. If we want to new a lot of CCString object, and add them into a CCArray,the following codes will achieve that and make your code more simple.

1 2        CCArray *stringArray = CCArray::create( 3 4            ccs("Hello"), 5 6            ccs("Variable"), 7 8            ccs("Size"), 910            ccs("!"),1112            NULL); come from: http://www.cocos2d-x.org/projects/cocos2d-x/wiki/CCString

转载于:https://www.cnblogs.com/Jzong/archive/2013/04/22/cocos2d-x-CCString.html

你可能感兴趣的文章
python 中time, datetime的用法
查看>>
python中将函数赋值给变量时需要注意的一些问题
查看>>
SAS数据挖掘实战篇【五】
查看>>
如何成为合格的数据分析师
查看>>
ArcGIS10.5资源分享
查看>>
理解http幂等性
查看>>
grep运用
查看>>
logstash收集syslog日志
查看>>
jenkins修改数据存放路径
查看>>
poj2481树状数组解二维偏序
查看>>
软件工程网络15个人阅读作业1(201521123062 杨钧宇)
查看>>
根据控制点坐标对完成坐标转换
查看>>
Boost.ASIO简要分析-4 多线程
查看>>
java调用支付宝接口代码介绍
查看>>
安装apache 后,找不到服务,解决办法
查看>>
【洛谷 T47488】 D:希望 (点分治)
查看>>
spring-MVC访问静态资源
查看>>
JavaScript异步加载与同步加载
查看>>
Eclipse搭建springboot项目(六)全局异常
查看>>
Android 报错:error: too many padding sections on bottom border
查看>>