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

来源:互联网 发布:淘宝文案招聘 编辑:程序博客网 时间:2024/05/18 13:31

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); //释放
}
 

 

0 0
原创粉丝点击