Skip to content

Latest commit

 

History

History
68 lines (51 loc) · 2.15 KB

wcerr.md

File metadata and controls

68 lines (51 loc) · 2.15 KB

wcerr

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

概要

wcerrは、標準エラー出力に対するワイド文字用の出力ストリームオブジェクトである。

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

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

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

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

wcerrはwide 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::wcerr << L"error: " << e.what() << std::endl;
  }
}
  • std::wcerr[color ff0000]
  • v.at[link /reference/vector/vector/at.md]
  • std::exception[link /reference/exception/exception.md]

出力例 (標準エラー出力)

error: vector::_M_range_check: __n (which is 42) >= this->size() (which is 0)

例外オブジェクトが保持するメッセージの内容は、処理系によって異なる。

バージョン

言語

  • C++98

備考

  • ワイド文字の出力が期待どおりに表示されない場合がある。ロケールや端末の設定についてはwcoutの備考を参照

出典

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

関連項目