Skip to content

Files

67 lines (52 loc) · 1.95 KB

cerr.md

File metadata and controls

67 lines (52 loc) · 1.95 KB

cerr

  • iostream[meta header]
  • std[meta namespace]
  • variable[meta id-type]
namespace std {
  extern ostream cerr;
  extern wostream wcerr;
}
  • ostream[link ../ostream/basic_ostream.md]
  • wostream[link ../ostream/basic_ostream.md]

概要

cerrwcerrも、標準エラー出力に対する出力ストリームオブジェクトである。

すなわち、std::basic_streambufから派生していて<cstdio>stderrオブジェクトに結びつけられているストリームバッファに出力する。

本オブジェクトは、初期化が完了すると tie()&cout を返すようになる。

clogと異なる点は、unitbufフラグが指定されていることである。そのため、出力操作のたびにバッファの吐き出しが行われる。

その他の状態は、basic_ios::init の事後条件と同様である。

cerrcharacter error (stream)を意味する。またwcerrwide character error (stream)を意味する。[1]

#include <iostream>
#include <vector>

int main()
{
  try
  {
    std::vector<int> v;
    v.at(42) = 1;
  }
  catch(const std::exception& e)
  {
    std::cerr << "問題発生: " << e.what() << std::endl;
  }
}
  • std::cerr[color ff0000]
  • v.at[link /reference/vector/vector/at.md]
  • std::exception[link /reference/exception/exception.md]

出力例

問題発生: invalid vector<T> subscript

出力内容は環境により異なる。

バージョン

言語

  • C++98

出典

  1. ^ Stroustrup: C++ Style and Technique FAQ(2018-08-21 17:01 JST 閲覧)

参照