<bdo id='rnYkq'></bdo><ul id='rnYkq'></ul>
      1. <i id='rnYkq'><tr id='rnYkq'><dt id='rnYkq'><q id='rnYkq'><span id='rnYkq'><b id='rnYkq'><form id='rnYkq'><ins id='rnYkq'></ins><ul id='rnYkq'></ul><sub id='rnYkq'></sub></form><legend id='rnYkq'></legend><bdo id='rnYkq'><pre id='rnYkq'><center id='rnYkq'></center></pre></bdo></b><th id='rnYkq'></th></span></q></dt></tr></i><div id='rnYkq'><tfoot id='rnYkq'></tfoot><dl id='rnYkq'><fieldset id='rnYkq'></fieldset></dl></div>
      2. <tfoot id='rnYkq'></tfoot>

      3. <legend id='rnYkq'><style id='rnYkq'><dir id='rnYkq'><q id='rnYkq'></q></dir></style></legend>

        <small id='rnYkq'></small><noframes id='rnYkq'>

        确定流结束时出现EOF问题

        时间:2023-10-18

          <bdo id='px92R'></bdo><ul id='px92R'></ul>
          <tfoot id='px92R'></tfoot>
        • <legend id='px92R'><style id='px92R'><dir id='px92R'><q id='px92R'></q></dir></style></legend>
        • <i id='px92R'><tr id='px92R'><dt id='px92R'><q id='px92R'><span id='px92R'><b id='px92R'><form id='px92R'><ins id='px92R'></ins><ul id='px92R'></ul><sub id='px92R'></sub></form><legend id='px92R'></legend><bdo id='px92R'><pre id='px92R'><center id='px92R'></center></pre></bdo></b><th id='px92R'></th></span></q></dt></tr></i><div id='px92R'><tfoot id='px92R'></tfoot><dl id='px92R'><fieldset id='px92R'></fieldset></dl></div>
            <tbody id='px92R'></tbody>

              <small id='px92R'></small><noframes id='px92R'>

                • 本文介绍了确定流结束时出现EOF问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我尝试使用函数 feof(FILE *) 确定文件结尾时,我发现它没有按预期工作:即使流结束,也需要额外读取.例如feof(FILE*) 如果在读取 10 个字节后立即调用具有 10 个字节数据的文件,则不会告诉 true.我需要一个额外的读取操作,当然返回 0,然后 feof(FILE *) 会说好的,现在你到了."

                  When I try to determine end of file with function feof(FILE *), I find it does not work as I expected: an extra read is required even if the stream does end. e.g. feof(FILE*) will not tell true if invoked on a file with 10 bytes data just after reading 10 bytes out. I need an extra read operation which of course return 0, then feof(FILE *) will say "OK, now you reach the end."

                  我的问题是为什么还需要一个 read 以及如何确定文件的结尾,或者如果我不想要 feof-style?

                  My question is why does one more read required and how to determine end of file or how to know how many bytes left in a file stream if I don't want the feof-style?

                  谢谢和最好的问候.

                  推荐答案

                  不要使用 feof() 或任何变体 - 就这么简单.您希望它以某种方式预测下一次读取将失败,但这不是它的作用 - 它告诉您上一次读取的结果是什么.读取文件的正确方法是(在伪代码中):

                  Do not use feof() or any variants - it is as simple as that. You want it to somehow predict the next read will fail, but that's not what it does - it tells you what the result of the PREVIOUS read was. The correct way to read a file is (in pseudocode):

                  while( read( file, buffer ) ) {
                     do something with buffer
                  }
                  

                  也就是说,需要测试读操作的结果.对于 C 流和 C++ iostream 都是如此.

                  In other words, you need to test the result of the read operation. This is true for both C streams and C++ iostreams.

                  这篇关于确定流结束时出现EOF问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 C++ 读取数字行 下一篇:使用 ifstream 读取文件

                  相关文章

                  <tfoot id='ZGNrx'></tfoot>

                  1. <small id='ZGNrx'></small><noframes id='ZGNrx'>

                    • <bdo id='ZGNrx'></bdo><ul id='ZGNrx'></ul>
                    <i id='ZGNrx'><tr id='ZGNrx'><dt id='ZGNrx'><q id='ZGNrx'><span id='ZGNrx'><b id='ZGNrx'><form id='ZGNrx'><ins id='ZGNrx'></ins><ul id='ZGNrx'></ul><sub id='ZGNrx'></sub></form><legend id='ZGNrx'></legend><bdo id='ZGNrx'><pre id='ZGNrx'><center id='ZGNrx'></center></pre></bdo></b><th id='ZGNrx'></th></span></q></dt></tr></i><div id='ZGNrx'><tfoot id='ZGNrx'></tfoot><dl id='ZGNrx'><fieldset id='ZGNrx'></fieldset></dl></div>
                    <legend id='ZGNrx'><style id='ZGNrx'><dir id='ZGNrx'><q id='ZGNrx'></q></dir></style></legend>