std::iostream_category
std::iostream_category (iostream 오류 카테고리)
iostream 오류에 대한 정적 오류 카테고리 객체의 참조를 얻는 함수예요. C++11부터 있어요.
출처: cppreference
본문
<ios> 헤더에 정의돼 있어요.
const std::error_category& iostream_category() noexcept;
iostream 오류에 대한 정적 오류 카테고리 객체의 참조를 얻어요. 이 객체는 가상 함수 error_category::name()을 오버라이드해 문자열 "iostream"을 가리키는 포인터를 반환해야 해요. std::ios_base::failure 타입의 예외에 제공되는 오류 코드를 식별하는 데 쓰여요.
매개변수
(없음)
반환값
std::error_category에서 파생된 미지정 런타임 타입의 정적 객체에 대한 참조예요.
예제
#include <fstream>
#include <iostream>
#include <system_error>
int main()
{
std::ios_base::iostate s;
try
{
std::ifstream f("nonexistent.txt");
f.exceptions(std::ios::failbit);
std::string line;
std::getline(f, line);
}
catch (const std::ios_base::failure& e)
{
// e.code() 의 category() == std::iostream_category()
std::cout << e.code() << '\n';
}
}