Using fstream on the Pokitto?

I’m trying to use std::fstream to save and load data from the SD card. I’m testing out the functions, and it doesn’t seem to be working. My code:
void saveCurrentWorld() { std::fstream saveFO; saveFO.open ("test.txt"); saveFO << "Testing...\n"; saveFO.close(); }
This is in main.cpp; both main.cpp and test.txt are in the root/Game folder of my project.

Anyone know why nothing is being written to test.txt?

1 Like

Don’t think fstream is suported, pokitto’s filesystem is not like on an operating system.
Look into pokittodisk in the library

1 Like

Okay, here’s my code right now:
fileOpen("test.txt",FILE_MODE_READWRITE); fileSetPosition(1); filePutChar(33); fileClose();
Nothing seems to be appearing in test.txt. I also tried setting the position to 0 and it still didn’t work.

Is the buffer something other than the file being opened?

Not sure but could you test if it finds the file?

‘‘‘
uint32_t IsFile = fileOpen(“test.txt”,FILE_MODE_READWRITE);
If(!IsFile)
// do game update here or something
‘‘‘

1 Like

Test.txt can not be an empty file, it has to be filled with dummy data

@jonne can you create files? like for a GAME.SAVE file or something

@epicdude312 sorry bit of a cross post but i see your doing a side scroller so this sample code will work for you since your only going to scroll in 1 direction Streaming map data from SD card test
ofcource this is read not write

The modded petitfatfs currently in use can not create files. Only read/write existing files.

While petitfatfs has good things (extremely small memory use), I have started looking at adding an optional switch for a more advanced SD library. There are many available on mbed, even with fstream support.

how bad are the others in terms of memory? having fstream would be nice if its not slow.
there are some issues with the current petitfatfs in terms of streaming data it seems

I can’t get it working. I’ve put test.txt files in the same folder as main.cpp, the same folder as the .cbp file, the root folder and the /Pokitto folder. Nothing works. I’ve also made all said test.txt files contain “TESTING” in them. Nothing is changing.

Did you already try the folder where the simulator exe is located?

1 Like

Yep…apparently I forgot to check that and everything’s working fine. Silly me.

2 Likes