Iphone 需要在C+中使用fopen写入文件+;iOS项目的类 我有一个使用C++类和FFMPEG的项目,我需要使用FOpenD并将文件写入到应用程序沙箱中,所以我需要用C++编写的代码相当于: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docs_dir = [paths objectAtIndex:0];

Iphone 需要在C+中使用fopen写入文件+;iOS项目的类 我有一个使用C++类和FFMPEG的项目,我需要使用FOpenD并将文件写入到应用程序沙箱中,所以我需要用C++编写的代码相当于: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docs_dir = [paths objectAtIndex:0];,iphone,c++,objective-c,ios,ffmpeg,Iphone,C++,Objective C,Ios,Ffmpeg,这将把我带到我的应用程序沙箱,在那里我几乎可以操纵我的文件 问题是我如何在C++中编写这个代码,这样我就可以在文件上使用fOpen/ 这是需要实施的方法: int testGrabAndWrite(const char* streamURL, bool decode, const char* filename) { FILE *outfile; int ret; int counter = 0; uint8_t *data; // Poi

这将把我带到我的应用程序沙箱,在那里我几乎可以操纵我的文件 问题是我如何在C++中编写这个代码,这样我就可以在文件上使用fOpen/ 这是需要实施的方法:

int testGrabAndWrite(const char* streamURL, bool decode, const char* filename)
{
    FILE *outfile;
    int ret;
    int counter = 0;
    uint8_t *data;              // Pointer to the received audio mem
    int size;                   // Size of the received audio buffer


    outfile = fopen(filename, "w");

    if (outfile == NULL)
        exit(1);

    // Open the RTP stream
    if ((ret = openStream(streamURL, decode)) < 0)
        return ret;

    // Print out info about the stream found
    int tmpSampleRate, tmpBitRate, tmpChannels;
    ret = getStreamInfo(tmpSampleRate, tmpBitRate, tmpChannels);
    printf("\nSample rate:%d Bit rateL%d Channels:%d\n",tmpSampleRate,tmpBitRate, tmpChannels);

    // Grab some sample data and write it to file.
    while (counter < 500) 
    {
        ret = getStreamData(data, size);
        fwrite(data, 1, size, outfile);                             // Write RTP packets, i.e. mp3, to file.
        printf("Wrote packet %d with size %d which returned %d. ", ++counter, size, ret);
    }

    fclose(outfile);
    closeStream();

    return ret;
}
int testgrabandwite(const char*streamURL,bool decode,const char*filename)
{
文件*输出文件;
int ret;
int计数器=0;
uint8_t*data;//指向接收到的音频内存的指针
int size;//接收到的音频缓冲区的大小
outfile=fopen(文件名,“w”);
if(outfile==NULL)
出口(1);
//打开RTP流
如果((ret=openStream(streamURL,decode))<0)
返回ret;
//打印找到的流的相关信息
int TMP采样率、TMP硝酸盐、TMP通道;
ret=getStreamInfo(tmpSampleRate、tmpBitRate、tmpChannel);
printf(“\n采样率:%d比特率%d个通道:%d\n”,tmpSampleRate,tmpBitRate,tmpChannel);
//获取一些示例数据并将其写入文件。
同时(计数器<500)
{
ret=getStreamData(数据、大小);
fwrite(数据,1,大小,输出文件);//将RTP数据包(如mp3)写入文件。
printf(“写入数据包%d,大小为%d,返回%d.”,++计数器,大小,ret);
}
fclose(输出文件);
closeStream();
返回ret;
}

消息>代码>文件系统表示>代码>重排一个字符文件,用于文件系统,例如可能转换为UTF-8/P><代码> fOpen.()/Cord>是C API,C++不是使用<代码> fStase<代码>类和朋友的C++。向我们展示您需要集成的类。创建一个.mm文件。。这样,你可以使用C++和目标CVE,这对于模拟器来说是有效的,但是文件在4GS上返回为空。不确定你们是否注意到了这一点。当我得到解决方案时,我会尝试添加它。@Dev2Rights:除非文件丢失或不可读,否则上述代码没有理由不能在实际设备上工作。

errno
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docs_dir = [paths objectAtIndex:0];
NSString* aFile = [docs_dir stringByAppendingPathComponent: @"somedocthatdefinitelyexists.doc"];

FILE* fp = fopen([aFile fileSystemRepresentation], "r");