C++ IOS 庫 - Errc



描述

此列舉類型別定義了 iostream 類別的錯誤條件。列舉至少包含如下所示的標籤:

io_errc 標籤 描述
1 流錯誤

所有庫實現至少定義此值(流,值為 1),但可能會提供其他值,特別是如果它們需要為 iostream 類別生成其他錯誤程式碼。

列舉型別 io_errc 的值可用於建立 error_condition 物件,以將其與 ios_base::failure 的 code 成員返回的值進行比較。

宣告

以下是 std::io_errc 函式的宣告。

enum class io_errc;;

引數

示例

下面的示例解釋了 std::io_errc 函式。

#include <iostream>

int main () {
   std::cin.exceptions (std::ios::failbit|std::ios::badbit);
   try {
      std::cin.rdbuf(nullptr);
   } catch (std::ios::failure& e) {
      std::cerr << "failure caught: ";
      if ( e.code() == std::make_error_condition(std::io_errc::stream) )
         std::cerr << "stream error condition\n";
      else
         std::cerr << "some other error condition\n";
   }
   return 0;
}

讓我們編譯並執行上面的程式,這將產生以下結果:

failure caught: stream error condition
ios.htm
廣告
© . All rights reserved.