C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了C fwrite()写的比预期的要多大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
复制文件遇到问题

码:

bool done;
    FILE* fin;
    FILE* fout;
    const int bs = 1024*64;//64 kb
    char* buffer[bs];
    int er,ew,br,bw;
    long long int size = 0;
    long long int sizew = 0;
    er = fopen_s(&fin,s.c_str(),"rb");
    ew = fopen_s(&fout,s2.c_str(),"wb");
    if(er == 0 && ew == 0){
        while(br = fread(buffer,1,bs,fin)){
            size += br;
            sizew += fwrite(buffer,fout);
        }
        done = true;
    }else{
        done = false;
    }
    if(fin != NULL)fclose(fin);
    if(fout != NULL)fclose(fout);

以某种方式fwrite写入整个缓冲区忽略计数值(br)

一些例子如何:

Copying 595 file of 635 DONE. 524288/524288 B
Copying 596 file of 635 DONE. 524288/524288 B
Copying 597 file of 635 DONE. 65536/145 B
Copying 598 file of 635 DONE. 65536/16384 B
Copying 599 file of 635 DONE. 65536/145 B
Copying 600 file of 635 DONE. 65536/67 B
Copying 601 file of 635 DONE. 65536/32768 B
Copying 602 file of 635 DONE. 65536/67 B

谁知道问题出在哪里?

解决方法@H_696_22@
你应该做

sizew += fwrite(buffer,fout);

你正在传递bs,这是允许fread读取的最大数量. br是fread实际读取的数量.

大佬总结

以上是大佬教程为你收集整理的C fwrite()写的比预期的要多全部内容,希望文章能够帮你解决C fwrite()写的比预期的要多所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。