std::ostream& operator<<

std::ostream& operator<< (std::error_code 출력)

std::error_code를 출력 스트림에 쓰는 연산자예요. 카테고리 이름과 값으로 표시해요. C++11부터 있어요.

출처: cppreference

본문

<system_error> 헤더에 정의돼 있고, std::error_code용 출력 연산자예요.

template< class CharT, class Traits >
std::basic_ostream<CharT, Traits>&
    operator<<( std::basic_ostream<CharT, Traits>& os, const error_code& ec );

오류 코드 ec를 스트림 os에 써요. 형식은 카테고리이름:값 형태예요.

os << ec.category().name() << ':' << ec.value();

예를 들어:

#include <system_error>
#include <iostream>

int main()
{
    std::error_code ec = std::errc::no_such_file_or_directory;
    std::cout << ec << '\n'; // "generic:2" (리눅스 등에서)
}

출력 형태가 name():value이므로, message()와 달리 코드의 원시 숫자 값을 함께 볼 수 있어요. 디버깅이나 오류 로그에 유용해요.

더 알아보기 (Learn more)

cppreference