I need to write a lot of integers to a binary file on Win32, iOS, and Android. Is there a way to do this? CCFileUtils only has a get method, not a write.
Chad Grenier wrote:
I need to write a lot of integers to a binary file on Win32, iOS, and Android. Is there a way to do this? CCFileUtils only has a get method, not a write.
You can use standard c interface to save your binary file.
Use CCFileUtils::getWriteablePath() to get the directory which is writeable.
For example,
char* pszDir = CCFileUtils::getWriteablePath().c_str();
FILE* fp = fopen(pszDir, "wb");
if (fp != NULL)
{
...
fwrite(...);
fclose(fp);
}
Thank you James. For storing a big list of floats and integers the file will be smaller as binary than ASCII correct?
Hey Chad,
I ran into a similar problem and decided to write everything to XML. There are some issues to doing this, but I feel it is well worth overcoming them since XML is fairly easy to work with and cross-platform. Here is a thread that discusses some of the problems I ran into. If you have questions, post them in the old thread and I’ll be happy to respond. The text got really screwed up, but hopefully it is still clear:
http://www.cocos2d-x.org/boards/6/topics/6691?r=6893#message-6893
Austin