Sur*_*ine 7 c++ iphone xcode ifstream ios
我正在尝试使用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 );
}
Run Code Online (Sandbox Code Playgroud)
我已将assets文件夹作为蓝色文件夹添加到XCode项目中,它显示在Targets-> Copy Bundle Resources中.
Jer*_*man 11
试试这个:
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4766 次 |
| 最近记录: |