virtual string message(int ev) const = 0;
概要
エラーコードに対応するメッセージを取得する
戻り値
エラーコードを説明するメッセージを返す
- C++11 : 文字列のエンコーディングは未規定(実装によってCロケールのエンコーディングだったり、Windowsのコードページ (ACP) だったりと移植可能に扱えなかった)
- C++29 : 文字列は、実行文字集合のマルチバイト文字列であると規定された
例
#include <iostream>
#include <system_error>
#include <string>
#include <cerrno>
int main()
{
const std::error_category& cat = std::generic_category();
std::string msg = cat.message(ENOTDIR);
std::cout << msg << std::endl;
}
出力
Not a directory
バージョン
言語
- C++11
処理系
- Clang: ??
- GCC: 4.6.1 ✅
- Visual C++: 2010 ✅
参照
- P3395R6 Fix encoding issues and add a
formatterforstd::error_code- C++29で、返される文字列のエンコーディングが規定された
- LWG Issue 4156.
error_categorymessages have unspecified encoding- エンコーディングが未規定であることを指摘したissue。P3395R6で解決された