다음을 통해 공유


Output Streams

An output stream object is a destination for bytes. The three most important output stream classes are ostream, ofstream, and ostringstream.

The ostream class, through the derived class basic_ostream, supports the predefined stream objects:

  • cout   standard output

  • cerr   standard error with limited buffering

  • clog   similar to cerr but with full buffering

Objects are rarely constructed from ostream; predefined objects are generally used. In some cases, you can reassign predefined objects after program startup. The ostream class, which can be configured for buffered or unbuffered operation, is best suited to sequential text-mode output. All functionality of the base class, ios, is included in ostream. If you construct an object of class ostream, you must specify a streambuf object to the constructor.

The ofstream class supports disk file output. If you need an output-only disk, construct an object of class ofstream. You can specify whether ofstream objects accept binary or text-mode data when constructing the ofstream object or when calling the open member function of the object. Many formatting options and member functions apply to ofstream objects, and all functionality of the base classes ios and ostream is included.

If you specify a filename in the constructor, that file is automatically opened when the object is constructed. Otherwise, you can use the open member function after invoking the default constructor.

Like the run-time function sprintf_s, the ostringstream class supports output to in-memory strings. To create a string in memory by using I/O stream formatting, construct an object of class ostringstream.

단원 내용

출력 스트림 개체 생성

삽입 연산자 사용 및 형식 제어

Output File Stream Member 함수

버퍼링 효과

이진 출력 파일

고유 클래스에 대해 << 연산자 오버로드

인수 없이 고유 조작자 작성

참고 항목

참조

ofstream

ostringstream

iostream 프로그래밍

기타 리소스

<ostream> 멤버

basic_ostream 멤버