Wednesday, October 7, 2026
HomeiOS Developmentios - Cannot open file streams for writing on iPhone with XCode...

ios – Cannot open file streams for writing on iPhone with XCode in C++

[ad_1]

I am engaged on a sport written in C++ and attempting to get it to work on iOS through XCode. Most issues appear to be working at this level, nonetheless, I can not write to recordsdata.

That is the code that masses the consumer’s save information (it is simply an int denoting how far into the sport they’ve made it). I can load this information simply effective with no issues.

    void ManagerState::LoadProgress()
    {
        std::ifstream saveFile;
        saveFile.open(mSavePath, std::ifstream::in);
        if(!saveFile)
        {
            Opal::Logger::LogString("Didn't open save file!");
        }
        else
        {
            saveFile >> mCurrentConversation;
            saveFile.shut();
        }
    }

Nonetheless, this code, which is sort of an identical, doesn’t work. I get this message printed to the console once I verify errno after attempting to open the file “Error Operation not permitted”. It looks as if I haven’t got write permission for the recordsdata that I copied to the machine.


    void ManagerState::SaveProgress()
    {
        std::ofstream saveFile;
        saveFile.open(mSavePath, std::ofstream::out | std::ofstream::trunc);

        char buffer[ 256 ];
        strerror_r( errno, buffer, 256 ); // get string message from errno, XSI-compliant model
        printf("Error %s", buffer);
        
        if(!saveFile)
        {
            Opal::Logger::LogString("Didn't open save file!");
        }
        else
        {
            saveFile << mCurrentConversation - 1;
            saveFile.shut();
        }
    }

That is the setup for copying assets to the machine.

I’ve tried

  • Utilizing SDL’s file I/O
  • Utilizing C-style file I/O (fopen)
  • not truncating the file

Nothing has labored.

Can anybody inform me find out how to both allow write permissions on the recordsdata I copied, or find out how to get them on the machine in a means that permits me to avoid wasting and browse information from them?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments