Click here to Skip to main content
13,000,469 members (57,840 online)
Rate this:
Please Sign up or sign in to vote.
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
NSString * filePath = [[NSBundle mainBundle] pathForResource:@"UserData"

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?


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 12-Jul-13 11:20am
Updated 12-Jul-13 15:35pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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 =>[^]

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 15 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100