basic_ostream Class

此模板类描述控制插入元素的对象和已编码的对象到流缓冲区中包含的元素类型的 Elem,也称为 char_type,其字符特性由类 Tr,也称为 traits_type

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

参数

  • _Elem
    char_type

  • _Tr
    字符traits_type

备注

该重载的大部分成员函数运算符 << 是一种格式化的输出函数。他们遵循以下模式:

   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 );

其他两个成员函数是未格式化的输出函数。他们遵循以下模式:

   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 );

这两个组的函数调用 setstate(badbit) 如果在插入元素时遇到故障。

对象的类 basic_istream <ElemTr> 将存储只虚拟公共基本对象类的 basic_ios< ElemTr >

示例

有关示例,请参阅basic_ofstream Class以了解有关输出流的详细信息。

5cf30x1h.collapse_all(zh-cn,VS.110).gif构造函数

basic_ostream

构造 basic_ostream 对象。

5cf30x1h.collapse_all(zh-cn,VS.110).gif成员函数

刷新

刷新缓冲区。

放置

将字符放在流中。

seekp

重置输出流中的位置。

卫士

嵌套的类描述的对象的声明结构的格式化的输出函数和未格式化的输出函数。

换用

交换所要进行这样的basic_ostream对象所提供的那些basic_ostream对象。

tellp

报告输出流中的位置。

write

将字符放在流中。

5cf30x1h.collapse_all(zh-cn,VS.110).gif运算符

operator=

将指定的值所提供的basic_ostream对象对该对象的参数。

运算符 <<

写入流。

要求

标题: <ostream>

命名空间: 标准

请参见

参考

线程安全性对标准C++库中

iostream编程

(mfc)约定

其他资源

basic_ostream 成员

ostream 成员