Using fstream on the Pokitto?


#1

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?


#2

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


#3

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?


#4

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
‘‘‘


#5

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


#6

@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


#7

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.


#8

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


#9

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.


#10

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


#11

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