不是个抽象类,但是他是C++流的基类.它提供了基本的缓冲区管理.它包含六个缓存区指针,三个分别是读指针(开头,结尾,当前),另外三个是写指针(开头,结尾,当前)
读开始指针 当前读指针 读结尾指针
_M_gbegin _M_gnext _M_gend
=========================================================
^ ^ ^
_M_pbegin _M_pnext _M_pend
写开始指针 当前写指针 写结尾指针
template <class_CharT, class_Traits>
classbasic_streambuf
{
friendclassbasic_istream<_CharT, _Traits>;
friendclassbasic_ostream<_CharT, _Traits>;
public: // Typedefs.
typedef_CharT char_type;
typedeftypename_Traits::int_type int_type;
typedeftypename_Traits::pos_type pos_type;
typedeftypename_Traits::off_type off_type;
typedef_Traits traits_type;
public: // Destructor.
virtual ~basic_streambuf() {}
public: // Locale-related functions.
localepubimbue(constlocale& __loc) {
this->imbue(__loc);
locale__tmp = _M_locale;
_M_locale = __loc;
return__tmp;
}
localegetloc() const { return_M_locale; }
public: // Buffer management.
//设置缓冲区和长度
basic_streambuf* pubsetbuf(char_type* __s, streamsize__n)
{ returnthis->setbuf(__s, __n); }
//设置缓冲区偏移量,简单调用seekoff()函数
pos_typepubseekoff(off_type__offset, ios_base::seekdir__way,
ios_base::openmode__mod = ios_base::in | ios_base::out)
{ returnthis->seekoff(__offset, __way, __mod); }
//设置缓冲区位置,简单调用seekpos()函数
pos_typepubseekpos(pos_type__sp,
ios_base::openmode__mod = ios_base::in | ios_base::out)
{ returnthis->seekpos(__sp, __mod); }
//放置缓冲区同步,简单调用sync()函数
intpubsync() { returnthis->sync(); }
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/