std::basic_ios

std::basic_ios (스트림 기반 클래스)

std::basic_streambuf 인터페이스를 가진 객체와 상호작용하는 기능을 제공하는 클래스예요. 여러 std::basic_ios 객체가 하나의 실제 std::basic_streambuf 객체를 가리킬 수 있어요.

출처: cppreference

본문

<ios> 헤더에 정의돼 있어요.

template<
    class CharT,
    class Traits = std::char_traits<CharT>
> class basic_ios : public std::ios_base;

클래스 std::basic_iosstd::basic_streambuf 인터페이스를 가진 객체와 상호작용하는 기능을 제공해요. 여러 std::basic_ios 객체가 하나의 실제 std::basic_streambuf 객체를 가리킬 수 있어요.

공통 문자 타입 typedef

  • std::iosstd::basic_ios<char>
  • std::wiosstd::basic_ios<wchar_t>

멤버 타입

멤버 타입 정의
char_type CharT
traits_type Traits(Traits::char_typeCharT가 아니면 ill-formed)
int_type Traits::int_type
pos_type Traits::pos_type
off_type Traits::off_type

공개 멤버 함수

  • (constructor) — 객체를 생성해요.
  • (destructor) [virtual] — 객체를 파괴해요.
  • operator= — 복사 대입은 삭제됨.

상태 함수: good(오류 없음), eof(EOF 도달), fail(논리·입출력 오류), bad(심각한 오류), exceptions(예외 마스크), state(상태 비트).

플래그 함수: setstate, clear, setf, unsetf, flags, copyfmt, fill.

기타: rdbuf(버퍼 접근·교체), tie(결합 스트림), imbue(로케일), narrow/widen(문자 변환), sentry 등.

예제

#include <iostream>
#include <sstream>

int main()
{
    std::istringstream s("abc");
    std::ios_base::iostate state = s.rdstate();
    // 기본적으로 failbit 는 예외를 던지지 않음
    int x;
    if (s >> x) std::cout << "ok";
    else std::cout << "conversion failed";  // 출력
}

더 알아보기 (Learn more)

cppreference