![](/img/trans.png)
[英]Caching hundreds of files on iOS app for 24-48 hours: all in Document folder or better in multiple folders?
[英]Files in folders not found in iOS app using C++
我正在尝试使用std :: ifstream在主要使用C ++编写的iOS应用程序中读取存储在assets文件夹及其子文件夹中的文件(相同的代码也用于其他非iOS项目),但是找不到它们。 示例:有一个文件assets / shaders / ortho2d.vert ,我正在尝试加载它:
std::ifstream vertFStream( vertFile ); // vertFile's contents is "assets/shaders/ortho2d.vert"
if (!vertFStream) {
std::cerr << vertFile << " missing!" << std::endl;
exit( 1 );
}
我已将assets文件夹作为蓝色文件夹添加到XCode项目中,它显示在Targets-> Copy Bundle Resources中。
尝试这个:
NSBundle *b = [NSBundle mainBundle];
NSString *dir = [b resourcePath];
NSArray *parts = [NSArray arrayWithObjects:
dir, @"assets", @"shaders", @"ortho2d.vert", (void *)nil];
NSString *path = [NSString pathWithComponents:parts];
const char *cpath = [path fileSystemRepresentation];
std::string vertFile(cpath);
std::ifstream vertFStream(vertFile);
您可能需要检查应用程序运行位置的相对路径,并可能使用完整路径来确保找到该文件。
打开失败的事实并不一定意味着找不到文件,此时它可能无法读取。 (权限不正确或文件已锁定)。
退出(1)是相当激烈的。
抱歉,但有些标点符号:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.