• <legend id='jWZUs'><style id='jWZUs'><dir id='jWZUs'><q id='jWZUs'></q></dir></style></legend>
  • <tfoot id='jWZUs'></tfoot>

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

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

      1. 什么可能导致流进入“坏"?状态?

        时间:2024-08-13
        • <tfoot id='TVNMn'></tfoot>
          <legend id='TVNMn'><style id='TVNMn'><dir id='TVNMn'><q id='TVNMn'></q></dir></style></legend>

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

              <bdo id='TVNMn'></bdo><ul id='TVNMn'></ul>
                  <tbody id='TVNMn'></tbody>
                <i id='TVNMn'><tr id='TVNMn'><dt id='TVNMn'><q id='TVNMn'><span id='TVNMn'><b id='TVNMn'><form id='TVNMn'><ins id='TVNMn'></ins><ul id='TVNMn'></ul><sub id='TVNMn'></sub></form><legend id='TVNMn'></legend><bdo id='TVNMn'><pre id='TVNMn'><center id='TVNMn'></center></pre></bdo></b><th id='TVNMn'></th></span></q></dt></tr></i><div id='TVNMn'><tfoot id='TVNMn'></tfoot><dl id='TVNMn'><fieldset id='TVNMn'></fieldset></dl></div>
                1. 本文介绍了什么可能导致流进入“坏"?状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 C++ 中,每个流都有一个 bad 位:

                  In C++, each stream has a bad bit:

                  该标志由在读取或写入数据时发生错误时对流执行的操作设置,通常会导致流的完整性丢失.

                  This flag is set by operations performed on the stream when an error occurs while read or writing data, generally causing the loss of integrity of the stream.

                  来源

                  什么会导致流失去完整性"并进入 bad 状态?这与 fail 状态不同,当输入流尝试将值存储到不能接受该值的变量中时(例如尝试将字符串存储到整数变量中),最常发生这种情况).

                  What would cause a stream to "lose integrity" and enter the bad state? This is not the same as the fail state, which most often occurs when an input stream attempts to store a value into a variable that cannot accept said value (such as attempting to store a string into an integer variable).

                  注意这个问题是c++文件坏位的更一般形式,即特定于文件输入流;这个问题不是一个完全重复的问题,因为它通常适用于输入和输出流.

                  Note that this question is a more general form of c++ file bad bit, which is specific to file input streams; this question is not an exact duplicate as it applies to both input and output streams in general.

                  推荐答案

                  根据 cppreference.com:

                  标准库在以下情况下设置badbit:

                  The standard library sets badbit in the following situations:

                  • 通过 put()write() 插入输出流失败原因.

                  • Insertion into the output stream by put() or write() fails for any reason.

                  通过 operator<<std::put_moneystd::put_time,无法完成,因为输出结束流已到达(构面的格式化输出函数,例如num_put::put()money_put::put(),返回一个迭代器 iter,例如iter.failed()==true)

                  Insertion into the output stream by operator<<, std::put_money or std::put_time, could not complete because the end of the output stream was reached (The facet's formatting output function such as num_put::put() or money_put::put(), returns an iterator iter such that iter.failed()==true)

                  Stream 是用 rdbuf() 的空指针构造的,或者putback()/unget() 在带有空 rdbuf() 的流上调用,或者传递给operator<<(basic_streambuf*)

                  Stream is constructed with a null pointer for rdbuf(), or putback()/unget() is called on a stream with a null rdbuf(), or a null pointer passed to operator<<(basic_streambuf*)

                  rdbuf()->sputbackc()rdbuf()->sungetc() 返回 traits::eof()putback() 或unget()`

                  rdbuf()->sputbackc() or rdbuf()->sungetc() return traits::eof() to putback() orunget()`

                  rdbuf()->pubsync() 返回 -1 到 sync(),到 flush(),或到unitbuf 流上的 ostream::sentry 析构函数

                  rdbuf()->pubsync() returns -1 to sync(), to flush(), or to the destructor of ostream::sentry on a unitbuf stream

                  任何成员函数在 I/O 操作期间抛出异常关联的流缓冲区(例如 sbumpc()xsputn()sgetc()overflow(), etc)

                  Exception is thrown during an I/O operation by any member function of the associated stream buffer (e.g. sbumpc(), xsputn(), sgetc(), overflow(), etc)

                  iword()pword() 中抛出异常(例如std::bad_alloc)

                  Exception is thrown in iword() or pword() (e.g. std::bad_alloc)

                  <小时>

                  这可能是选择 cppreference.com 而不是 www.cpluplus.com 的另一个原因,请参阅:cplusplus.com 有什么问题?

                  这篇关于什么可能导致流进入“坏"?状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    <bdo id='Jf1o2'></bdo><ul id='Jf1o2'></ul>

                    <tfoot id='Jf1o2'></tfoot>
                  • <small id='Jf1o2'></small><noframes id='Jf1o2'>

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

                        • <legend id='Jf1o2'><style id='Jf1o2'><dir id='Jf1o2'><q id='Jf1o2'></q></dir></style></legend>