userDefault是一个单例,通过userDefault::getInstance();获得这个类的实例。userDefault使用哈希表结构,key-value,key索引,value为值
userDefault->setStringForKey(“key1”,”Value”);
userDefault->setBoolForKey(“key2”true);
userDefault->setFloatForKey(“key3”,23.4);
userDefault->setDoubleForKey(“key4”,12.3);
userDefault->setIntegerForKey(“key5”,12);
userDefault->flush();//将数据写入文件
文件路径
//获取可以写的路径
std::string path = FileUtils::getInstance()->getWritablePath();
//拼接路径(doucunments下的路径)
std::string xmlPath = path + std::string(data.xml);
log(“%s”,xmlPath.c_str;);
//获取app里面的data路径
std::string path2 = FileUtils ::getInstance()->fullPathForFilename(“data.xml”);
log(“%s”,path2.c_str);