VC++ 读取二进制文件以及写入文件简单示例

void main()
{
//读
    FILE *pFile=fopen("C:\\1.jpg","rb");
    char *pBuf;
    fseek(pFile,0,SEEK_END);  //定位到文件末尾
    int len=ftell(pFile);  //求文件长度
    pBuf=new char[len+1];
    rewind(pFile);  //重新定位指针到文件开始处
    fread(pBuf,1,len,pFile);
    fclose(pFile);

//写入刚才读取的文件
    FILE *pFileOut=fopen("C:\\2.jpg","wb");
    fwrite(pBuf,1,len,pFileOut);
    fclose(pFileOut);
    free(pBuf); //释放
}
 

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

 

posted @ 2014-06-21 17:37  十点听风  阅读(687)  评论(0编辑  收藏  举报