C++ 标准库IO(2) - basic-ios
basic-ios是ios_base的子类,同是它是一个泛型类,首先我们来看看它的定义,
template<typename _CharT, typename _Traits>
class basic_ios : public ios_base
{
…………
}
公共的属性只有几个类型,
typedef _CharT char_type; typedef typename _Traits::int_type int_type; typedef typename _Traits::pos_type pos_type; typedef typename _Traits::off_type off_type; typedef _Traits traits_type; //@} //@{ /** * These are non-standard types. */ typedef ctype<_CharT> __ctype_type; typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> > __num_put_type; typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> > __num_get_type;
定义了一些保护字段
protected: basic_ostream<_CharT, _Traits>* _M_tie; mutable char_type _M_fill; mutable bool _M_fill_init; basic_streambuf<_CharT, _Traits>* _M_streambuf; // Cached use_facet<ctype>, which is based on the current locale info. const __ctype_type* _M_ctype; // For ostream. const __num_put_type* _M_num_put; // For istream. const __num_get_type* _M_num_get;
以公开的形式继续对父类定义的状态做了进一步封装,同是定义了填充字符属性。定义了streambuf属性。
如:good()函数用于判断当前类输入状态是否处于正确输入状态,bad()判断输入状态是否为错误状态等。