⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_38647.htm

📁 vc
💻 HTM
字号:
<p>
序号:38647 发表者:hiha 发表日期:2003-05-05 09:42:03
<br>主题:文件处理问题
<br>内容:假设我有一个dat文件,文件有13678个byte,但每次我只要读1Kbyte.我这样写程序。&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BYTE *pbRead = new BYTE[1024];//1kB字节<BR>&nbsp;&nbsp;&nbsp;&nbsp;BYTE *pbBuf = new BYTE[1024];//1kB字节<BR>&nbsp;&nbsp;&nbsp;&nbsp;for(int i=0;i&lt;14;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!ReadFile(hFile,pbRead,1024,&amp;dwRead,NULL))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("error read");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memcpy(pbBuf,pbRead,1024);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//计算<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoSomeOtherWork(pbBuf,1024);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>1024*13=13312&lt;13678&lt;1024*14=14336,我取14,程序能正常读取吗?好像运行没问题,但就是不知道结果是不是正确。也就是说,在读到文件末尾时程序会自动跳出循环吗?谢谢!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:Neil Gan 回复日期:2003-05-05 10:18:57
<br>内容:1. the loop will come to an end.<BR>2. at the last time when ReadFile returns, dwRead is not 1024, it is 14336-13*1024, so in the memcpy and DoSomeOtherWork, you should use dwRead as the argument, not 1024.<BR>3. What is pbRead? why do you copy the content to pubBuf? why don't you use pbBuf as the buf? You can save the call to memcpy this way.<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:hiha 回复日期:2003-05-05 19:19:02
<br>内容:thanks for ur kind answering.i use double buffer cause i want to use asynchronous file operation,that is,reading the data and doing the computing work altogether.thank u again! 
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -