Click here to Skip to main content
Rate this: bad
good
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"
                                                      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 12-Jul-13 12:20pm
Edited 12-Jul-13 16:35pm
v2

1 solution

Rate this: bad
good
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 => http://www.techotopia.com/index.php/Working_with_Directories_on_iPhone_OS[^]
 

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

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

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 Maciej Los 270
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 202
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


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