Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm making a game for iPhone and my game object is in C++ and I save and load user data from that class. I am using a text file and std::ifstream and std::ofstream for reading and writing. During development I've just been dragging the text file from my Supporting Files folder to between the two "" in my code and I get a path which has worked for testing. Now I'd like to finalize that code so that it will work on users' devices.

Is there a way I can get, or hard-code a file path without using Objective-C, as in
C#
NSString * filePath = [[NSBundle mainBundle] pathForResource:@"UserData"
                                                      ofType:@"txt"];

If not, what would be a good way to engineer getting the file path? Can I do it in a way without using Objective-C in my C++ class? The question is really about coding style and design for portability, since the game will be ported to Android devices.

I was reading a little bit about sand-boxing. Should I make efforts to safeguard my file or can I get away without it?

Edit:

I've thought of this, creating a function in the Objective-C view that gets the path and calling that from the C++ class, but then I'd have to have a pointer to the Objective-C class in the C++ class.

Or, have the Objective-C class call a setter function of the c++ class when things start up.

I just haven't done enough of this to know good style.
Posted
Updated 12-Jul-13 15:35pm
v2

1 solution

you should be a good citizen and use the apple way for files on the device. That will also help to make backups or move in the iCloud.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

some fine material => http://www.techotopia.com/index.php/Working_with_Directories_on_iPhone_OS[^]


PS: here is more Windows stuff, at stackoverflow is obj-c ;-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900