此模板类描述控制插入元素的对象和已编码的对象到流缓冲区中包含的元素类型的 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 <Elem, Tr> 将存储只虚拟公共基本对象类的 basic_ios< Elem, Tr >。
示例
有关示例,请参阅basic_ofstream Class以了解有关输出流的详细信息。
构造函数
构造 basic_ostream 对象。 |
成员函数
刷新缓冲区。 |
|
将字符放在流中。 |
|
重置输出流中的位置。 |
|
嵌套的类描述的对象的声明结构的格式化的输出函数和未格式化的输出函数。 |
|
交换所要进行这样的basic_ostream对象所提供的那些basic_ostream对象。 |
|
报告输出流中的位置。 |
|
将字符放在流中。 |
运算符
将指定的值所提供的basic_ostream对象对该对象的参数。 |
|
写入流。 |
要求
标题: <ostream>
命名空间: 标准