1. 获取已经添加到xcode工程中的某一资源文件 file.txt 的路径
NSString *filePath_= [[NSBundle mainBundle] pathForResource:@"file" ofType:@"txt"]; std::string filePath =std::string([filePath_ UTF8String]);
2. 对当前xcode工程开通沙盒权限后,访问存储到手机上的某一资源文件夹sources/file.txt的路径
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; NSString *fileDir = [docDir stringByAppendingPathComponent:@"sources"]; NSString *filePath = [fileDir stringByAppendingPathComponent:@"file.txt"]; std::string filePath_=std::string([filePath UTF8String]);