问题描述
我正在为iPhone制作游戏,我的游戏对象是C ++,我保存并加载了该类中的用户数据.我正在使用文本文件以及std :: ifstream和std :: ofstream进行读写.在开发过程中,我只是将文本文件从我的Supporting Files文件夹中拖动到代码中的两个"之间,因此我得到了一条用于测试的路径.现在,我想完成该代码,以便它可以在用户的设备上运行.
有没有一种方法可以使用Objective-C获取或硬编码文件路径 ,如
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"];
如果没有,那么工程师获得文件路径的好方法是什么?我可以在不使用C ++类中使用Objective-C的情况下做到这一点吗?问题实际上是关于可移植性的编码样式和设计,因为该游戏将被移植到Android设备上.
我在阅读一些有关沙盒的知识.我应该努力保护我的文件,还是没有文件我可以逃脱吗?
我已经想到了这一点,在Objective-C视图中创建一个获取路径并从C ++类调用它的函数,但是然后我必须在C ++类中有一个指向Objective-C类的指针.
或者,在事情开始时让Objective-C类调用c ++类的setter函数.
我只是做不到足够的事情来了解好的样式.
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.
推荐答案
这篇关于除了使用Objective-C之外,还有其他方法可以在iOS中获取文件路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!