I have an unsigned long long variable (64-bits) that I would like to save to disk and retrieve later.
The obvious way is to use the CCUserDefault class, but it seems like all the types are less than 64 bits, expect for the string type which seems to be the only hope. So, How should I approach this?!
I know, some people say it’s trivial to implement your own saving type, but why bother? what happens if the API changes or the cocos2d-x guys add a support for a new platform?
Another why is to probably:
int firstPart = (int)(longInt & 0x00000000FFFFFFFFull);
int secondPart = (int)(longInt >> 32);
// save those two parts separately.
// dummy number
unsigned long long num = 0xFFFFFFFFFFFFFFFFull;
memcpy(byte_array, &num, sizeof(unsigned long long));
byte_array = ‘’;
// SAVE STRING TO CCUserDefault
unsigned long long another;
memcpy(&another, str.c_str(), sizeof(unsigned long long));
std::cout << another << std::endl;
… Actually, I think I’ll go with one of those methods.