std::basic_ostream

std::basic_ostream (출력 스트림)

문자 스트림에 대한 고수준 출력 연산을 제공하는 클래스 템플릿이에요. 형식화·비형식화 출력을 지원해요. 기반 basic_streambuf의 인터페이스로 구현돼요.

출처: cppreference

본문

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

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

클래스 템플릿 basic_ostream은 문자 스트림에 대한 고수준 출력 연산을 제공해요. 지원하는 연산에는 형식화 출력(예: 정수 값)과 비형식화 출력(예: 원시 문자·문자 배열)이 있어요. 이 기능은 basic_ios 기반 클래스를 통해 접근하는 basic_streambuf 클래스가 제공하는 인터페이스로 구현돼요. 전형적인 구현에서 basic_ostream은 상속되지 않은 데이터 멤버가 없어요.

공통 문자 타입 typedef

  • std::ostreamstd::basic_ostream<char>
  • std::wostreamstd::basic_ostream<wchar_t>

전역 객체

표준 라이브러리는 여섯 개의 전역 basic_ostream 객체를 제공해요. std::cout(표준 C 출력 stdout), std::cerr(표준 C 오류), std::clog, 그리고 wide 버전 wcout·wcerr·wclog.

멤버 함수

  • (constructor / destructor) — 객체 생성·파괴.
  • operator<< — 형식화 출력.
  • put — 문자 쓰기.
  • write — 문자 블록 쓰기.
  • flush — 버퍼 비우기.
  • seekp / tellp — 출력 위치 조정·조회.
  • print / println (C++23) — 형식 문자열로 출력.

예제

#include <iostream>

int main()
{
    std::cout << "Hello, world!\n";          // 형식화 출력
    std::cout.put('A');                       // 문자 쓰기
    std::cout.write("BC", 2);
    std::cout << std::endl;                   // 개행 + flush
}

더 알아보기 (Learn more)

cppreference