我想知道如何从C++文件打开应用程序包中的文件.
IE我有一个文件"manifest.xml",它开始被复制到应用程序包中.我需要一种从C++到加载此文件的方法.我认为它将涉及在Obj-C代码中设置一个路径,以便该文件位于工作目录中.
您必须使用CoreFoundation(C)或Foundation(ObjC).您可以使用CFBundle/ NSBundlefunctions 访问应用包中的每个对象("主包").
在CoreFoundation中你做(省略NULL检查):
CFURLRef manifest_url = CFBundleCopyResourceURL(CFBundleGetMainBundle(),
CFSTR("manifest"), CFSTR("xml"),
NULL);
char manifest_path[1024];
CFURLGetFileSystemRepresentation(manifest_url, true,
manifest_path, sizeof(manifest_path));
CFRelease(manifest_url);
FILE* f = fopen(manifest_path, "r"); // etc.
Run Code Online (Sandbox Code Playgroud)
在基金会你做
NSString* manifest_string = [[NSBundle mainBundle] pathForResource:@"manifest"
ofType:@"xml"];
const char* manifest_path = [manifest_string fileSystemRepresentation];
FILE* f = fopen(manifest_path, "r"); // etc.
Run Code Online (Sandbox Code Playgroud)