Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ STL Objective-C portability , +
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 12:20pm
Edited 12-Jul-13 16: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 Wink | ;-)

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

  Print Answers RSS
0 OriginalGriff 455
1 Sergey Alexandrovich Kryukov 312
2 DamithSL 179
3 King Fisher 179
4 Peter Leow 154
0 OriginalGriff 240
1 Maciej Los 95
2 Sascha Lefévre 85
3 King Fisher 70
4 F-ES Sitecore 55

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 15 Jul 2013
Copyright © CodeProject, 1999-2015
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