How to save file permanently to user device

Hi everyone,

I just noticed that whenever i compiled and re-deploy my game on test device, my saved file has been replaced with newly created file, that’s mean if i update my game to newer version, all users record will be lost. Right now, my method look like this:

std::string path = FileUtils::getInstance()->getWritablePath() + “\Player_Data.dat”;
std::ifstream readData(path, std::ios::binary);

if (readData.is_open())
{
       //if file existed, read data from file
    readData.read((char*)&_playerData, sizeof(PlayerData));
}
else
{
       //if not, create new file with default value
    _playerData.bestScore = 0;
    saveToFile();
}
readData.close();

Do anybody have a suggestion?

Hi,

Is it for Android version of the app?

There was topic , with suggestion to change adb deploy script to not uninstall app, but reinstalling app. Or your issue is with your code logic, that you overwriting save file in any case?

Thanks for replying, maybe the problem is with change the deploy script to reinstalling app. How can i do that?

Look here…

Check over there

Yeah! this is what i want. It’s work great! Thanks everyone :heart_eyes: :heart_eyes: