设置、数值-【Cocos2D-X 】初窥门径(11)CCUserDefault:保存数据-by小雨

在写这篇文章之前,xxx已经写过了几篇关于改设置、数值-主题的文章,想要了解的朋友可以去翻一下之前的文章

    保存单简的数据用CCUserDefault和Android中的SharedPreferences一样,都是以键值对存储的。

    

//获得bool型值
 bool getBoolForKey(const char* pKey, bool defaultValue = false);
 //获得整型值
 int  getIntegerForKey(const char* pKey, int defaultValue = 0);
//获得浮点数值
 float getFloatForKey(const char* pKey, float defaultValue=0.0f);
 //获得双精度浮点数值
 double  getDoubleForKey(const char* pKey, double defaultValue=0.0);
//获得字符串
 std::string getStringForKey(const char* pKey, const std::string & defaultValue = "");
 
 
//设置尔布型值
void setBoolForKey(const char* pKey, bool value);
 //设置整型值
 void setIntegerForKey(const char* pKey, int value);
 //设置浮点数值
 void setFloatForKey(const char* pKey, float value);
 //双精度浮点数值
 void setDoubleForKey(const char* pKey, double value);
 //设置字符串值
 void setStringForKey(const char* pKey, const std::string & value);

    用法:

CCUserDefault::sharedUserDefault()->setStringForKey("UserName","henn");

    

    

    载转请注明出处:http://blog.csdn.net/Vestigge

    

    

    

文章结束给大家分享下程序员的一些笑话语录: 开发时间
  项目经理: 如果我再给你一个人,那可以什么时候可以完工?程序员: 3个月吧!项目经理: 那给两个呢?程序员: 1个月吧!
项目经理: 那100呢?程序员: 1年吧!
项目经理: 那10000呢?程序员: 那我将永远无法完成任务.

posted @ 2013-04-16 13:37  坚固66  阅读(166)  评论(0编辑  收藏  举报