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

        <legend id='B6eoj'><style id='B6eoj'><dir id='B6eoj'><q id='B6eoj'></q></dir></style></legend>

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

        C++ ifstream failbit 和 badbit

        时间:2023-08-25

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

        • <tfoot id='uj2ac'></tfoot>
            • <bdo id='uj2ac'></bdo><ul id='uj2ac'></ul>
                <tbody id='uj2ac'></tbody>

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

                  <legend id='uj2ac'><style id='uj2ac'><dir id='uj2ac'><q id='uj2ac'></q></dir></style></legend>
                  本文介绍了C++ ifstream failbit 和 badbit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在C++中ifstream的情况下,failbitbadbit标志是在什么情况下设置的?

                  In case of ifstream in C++, under what conditions are failbit and badbit flags set ?

                  推荐答案

                  根据cplusplus.com:

                  failbit 通常由输入操作设置,当错误与操作本身的内部逻辑相关时,因此可能对流进行其他操作.而 badbit 通常在错误涉及流完整性丢失时设置,即使对流执行不同的操作,这种情况也可能持续存在.badbit 可以通过调用成员函数 bad 来独立检查.

                  failbit is generally set by an input operation when the error was related to the internal logic of the operation itself, so other operations on the stream may be possible. While badbit is generally set when the error involves the loss of integrity of the stream, which is likely to persist even if a different operation is performed on the stream. badbit can be checked independently by calling member function bad.

                  简单的词中,如果您在期望检索信件时得到一个数字,那就是failbit.如果发生严重错误,这会破坏从流中读取的能力 - 这是一个badbit.

                  In simple words, if you get a number when expect to retrieve a letter, it's failbit. If a serious error happens, which disrupts the ability to read from the stream at all - it's a badbit.

                  除了提到的标志,还有第三个非常相似——eofbit.您可以使用以下几个函数检查状态:ios::failios::goodios::bad

                  Except mentioned flags there is a third quite similar — eofbit. You can check the state using several functions: ios::fail, ios::good and ios::bad

                  您可以熟悉iostream 库 也在 MSDN 资源中.

                  And you can get familiar with iostream library at MSDN resource too.

                  最后,如果您在从文件读取(或访问某个文件或目录)时搜索如何处理所有错误位和异常的正确解决方案,我强烈建议您阅读一篇非常全面且写得很好的文章使用ifstream在C++中读取文件:正确处理badbit、failbit、eofbit和perror()",最后你会发现一些理想的解决方案.这篇文章确实值得一读.

                  Finally, if you search for the correct solution of how to handling all error bits and exceptions while reading from the file (or accessing some file or directory), I highly recommend you read a very comprehensive and well-written article "Reading files in C++ using ifstream: dealing correctly with badbit, failbit, eofbit, and perror()", at the end of which you will find a few Ideal solutions. The article is worth to read indeed.

                  这篇关于C++ ifstream failbit 和 badbit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从目录中读取文件名 下一篇:正确读取和写入 std::vector 到文件中

                  相关文章

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

                      <legend id='CHj4u'><style id='CHj4u'><dir id='CHj4u'><q id='CHj4u'></q></dir></style></legend>