다음을 통해 공유


basic_ostream 클래스

This template class describes an object that controls insertion of elements and encoded objects into a stream buffer with elements of type Elem, also known as char_type, whose character traits are determined by the class Tr, also known as traits_type.

template <class _Elem, class _Tr = char_traits<Elem> > 
   class basic_ostream 
       : virtual public basic_ios<_Elem, _Tr>

매개 변수

  • _Elem
    char_type

  • _Tr
    The character traits_type.

설명

Most of the member functions that overload operator<< are formatted output functions. They follow the pattern:

   iostate state = goodbit;
   const sentry ok( *this );
   if ( ok )
      {try
         {<convert and insert elements
         accumulate flags in state> }
      catch ( ... )
         {try
           {setstate( badbit ); }
         catch ( ... )
           {}
         if ( ( exceptions( ) & badbit ) != 0 )
           throw; }}
   width( 0 );    // Except for operator<<(Elem)
   setstate( state );
   return ( *this );

Two other member functions are unformatted output functions. They follow the pattern:

   iostate state = goodbit;
   const sentry ok( *this );
   if ( !ok )
      state |= badbit;
   else
      {try
         {<obtain and insert elements
         accumulate flags in state> }
      catch ( ... )
         {try
            {setstate( badbit ); }
         catch ( ... )
            {}
         if ( ( exceptions( ) & badbit ) != 0 )
            throw; }}
   setstate( state );
   return ( *this );

Both groups of functions call setstate(badbit) if they encounter a failure while inserting elements.

An object of class basic_istream<Elem, Tr> stores only a virtual public base object of class basic_ios<Elem, Tr>.

예제

See the example for basic_ofstream 클래스 to learn more about output streams.

생성자

basic_ostream

basic_ostream 개체를 생성합니다.

멤버 함수

flush

Flushes the buffer.

put

Puts a character in a stream.

seekp

Resets position in output stream.

sentry

The nested class describes an object whose declaration structures the formatted output functions and the unformatted output functions.

스왑

Exchanges the values of this basic_ostream object for those of the provided basic_ostream object.

tellp

Reports position in output stream.

write

Puts characters in a stream.

연산자

operator=

Assigns the value of the provided basic_ostream object parameter to this object.

함수입니다.<<

스트림에 씁니다.

요구 사항

Header: <ostream>

네임스페이스: std

참고 항목

참조

C++ 표준 라이브러리의 스레드 보안

iostream 프로그래밍

iostreams 규칙

기타 리소스

basic_ostream 멤버

<ostream> 멤버