I’m using android the the code below, no issues.
I first write out the length of the array as the first value and then loop through my array writing out each value
LevelProgress is my struct holding the level info.
std::string path = CCFileUtils::sharedFileUtils()->getWriteablePath() + "\\levelProgress.f";
FILE* f = fopen(path.c_str(), "wb");
int size = _levelProgress.size();
fwrite(&size, sizeof(int), 1, f);
for(unsigned int i = 0; i<_levelProgress.size(); i++)
{
fwrite(&_levelProgress[i], sizeof(LevelProgress), 1, f);
}
fclose(f);
CCFileUtils::getWriteablePath returns the correct path on each platform where you can safely read and write files to / from.
I could have used CCUserDefault (which is where I’m saving my settings like volume).
I wanted to store my info in a proper structure but CCUserDefault only supports simple types.
If cocos2dx supported proper object xml serialisation I would have used that but the way I’m doing it was quicker to implement.