📄 streambu.html
字号:
positions for the controlled streams.The new position is <CODE>sp</CODE>.</P><P>Typically, if<CODE>which & ios_base::in</CODE> is nonzero,the input stream is affected, and if <CODE>which & ios_base::out</CODE>is nonzero, the output stream is affected. Actual use of this parametervaries among derived stream buffers, however.</P><P>If the function succeeds in altering the stream position(s),it returns the resultant stream position (or one of them).Otherwise, it returns an invalid stream position.The default behavior is to return an invalid stream position.</P><H3><A NAME="streambuf::setbuf"><CODE>streambuf::setbuf</CODE></A></H3><PRE>virtual streambuf *<B>setbuf</B>(char_type *buffer, streamsize count);</PRE><P>The protected virtual member function performs an operationparticular to each derived stream buffer. (See, for example,<CODE><A HREF="fstream.html#filebuf">filebuf</A></CODE>.)The default behavior is to return <CODE>this</CODE>.</P><H3><A NAME="streambuf::setg"><CODE>streambuf::setg</CODE></A></H3><PRE>void <B>setg</B>(char_type *gbeg, char_type *gnext, char_type *gend);</PRE><P>The member function stores <CODE>gbeg</CODE> in the beginning pointer,<CODE>gnext</CODE> in the next pointer,and <CODE>gend</CODE> in the end pointer for the<A HREF="#input buffer">input buffer</A>.</P><H3><A NAME="streambuf::setp"><CODE>streambuf::setp</CODE></A></H3><PRE>void <B>setp</B>(char_type *pbeg, char_type *pend);</PRE><P>The member function stores <CODE>pbeg</CODE> in the beginning pointer,<CODE>pbeg</CODE> in the next pointer,and <CODE>pend</CODE> in the end pointer for the<A HREF="#output buffer">output buffer</A>.</P><H3><A NAME="streambuf::sgetc"><CODE>streambuf::sgetc</CODE></A></H3><PRE>int_type <B>sgetc</B>();</PRE><P>If a <A HREF="#read position">read position</A> is available,the member function returns<CODE>traits_type::<A HREF="string2.html#char_traits::to_int_type">to_int_type</A>(*<A HREF="#streambuf::gptr">gptr</A>())</CODE>Otherwise, it returns<CODE><A HREF="#streambuf::underflow">underflow</A>()</CODE>.</P><H3><A NAME="streambuf::sgetn"><CODE>streambuf::sgetn</CODE></A></H3><PRE>streamsize <B>sgetn</B>(char_type *ptr, streamsize count);</PRE><P>The member function returns<CODE><A HREF="#streambuf::xsgetn">xsgetn</A>(ptr, count)</CODE>.</P><H3><A NAME="streambuf::showmanyc"><CODE>streambuf::showmanyc</CODE></A></H3><PRE>virtual streamsize <B>showmanyc</B>();</PRE><P>The protected virtual member function returns a count of thenumber of characters that can be extracted from the inputstream with no fear that the program will suffer an indefinitewait. The default behavior is to return zero.</P><H3><A NAME="streambuf::snextc"><CODE>streambuf::snextc</CODE></A></H3><PRE>int_type <B>snextc</B>();</PRE><P>The member function calls<CODE><A HREF="#streambuf::sbumpc">sbumpc</A>()</CODE> and,if that function returns<CODE>traits_type::<A HREF="string2.html#char_traits::eof">eof</A>()</CODE>,returns <CODE>traits_type::eof()</CODE>.Otherwise, it returns<CODE><A HREF="#streambuf::sgetc">sgetc</A>()</CODE>.</P><H3><A NAME="streambuf::sputbackc"><CODE>streambuf::sputbackc</CODE></A></H3><PRE>int_type <B>sputbackc</B>(char_type ch);</PRE><P>If a <A HREF="#putback position">putback position</A> is availableand <CODE>ch</CODE> compares equal to the character stored in that position,the member function decrements the next pointer for the<A HREF="#input buffer">input buffer</A> and returns<CODE>traits_type::<A HREF="string2.html#char_traits::to_int_type">to_int_type</A>(ch)</CODE>.Otherwise, it returns<CODE><A HREF="#streambuf::pbackfail">pbackfail</A>(ch)</CODE>.</P><H3><A NAME="streambuf::sputc"><CODE>streambuf::sputc</CODE></A></H3><PRE>int_type <B>sputc</B>(char_type ch);</PRE><P>If a <A HREF="#write position">write position</A> is available,the member function stores <CODE>ch</CODE> in the write position,increments the next pointer for the<A HREF="#output buffer">output buffer</A>, and returns<CODE>traits_type::<A HREF="string2.html#char_traits::to_int_type">to_int_type</A>(ch)</CODE>.Otherwise, it returns<CODE><A HREF="#streambuf::overflow">overflow</A>(ch)</CODE>.</P><H3><A NAME="streambuf::sputn"><CODE>streambuf::sputn</CODE></A></H3><PRE>streamsize <B>sputn</B>(const char_type *ptr, streamsize count);</PRE><P>The member function returns<CODE><A HREF="#streambuf::xsputn">xsputn</A>(ptr, count)</CODE>.</P><H3><A NAME="streambuf::stossc"><CODE>streambuf::stossc</CODE></A></H3><PRE>void <B>stossc</B>(); <B>[optional]</B></PRE><P>The member function calls<CODE><A HREF="#streambuf::sbumpc">sbumpc</A>()</CODE>.Note that an implementation is not required to supply this member function.</P><H3><A NAME="streambuf::sungetc"><CODE>streambuf::sungetc</CODE></A></H3><PRE>int_type <B>sungetc</B>();</PRE><P>If a <A HREF="#putback position">putback position</A> is available,the member function decrements the next pointer for the<A HREF="#input buffer">input buffer</A> and returns<CODE>traits_type::<A HREF="string2.html#char_traits::to_int_type">to_int_type</A>(*<A HREF="#streambuf::gptr">gptr</A>())</CODE>.Otherwise it returns<CODE><A HREF="#streambuf::pbackfail">pbackfail</A>()</CODE>.</P><H3><A NAME="streambuf::sync"><CODE>streambuf::sync</CODE></A></H3><PRE>virtual int <B>sync</B>();</PRE><P>The protected virtual member function endeavors to synchronizethe controlled streams with any associated external streams.Typically, this involves writing out any elements between the beginningand next pointers for the<A HREF="#output buffer">output buffer</A>.It does <I>not</I> involve putting back any elements between the nextand end pointers for the<A HREF="#input buffer">input buffer</A>.If the function cannot succeed, it returns -1.The default behavior is to return zero.</P><H3><A NAME="streambuf::traits_type"><CODE>streambuf::traits_type</CODE></A></H3><PRE>typedef char_traits <B>traits_type</B>;</PRE><P>The type is a synonym for<CODE><A HREF="string2.html#char_traits">char_traits</A></CODE>.</P><H3><A NAME="streambuf::uflow"><CODE>streambuf::uflow</CODE></A></H3><PRE>virtual int_type <B>uflow</B>();</PRE><P>The protected virtual member function endeavors to extract the currentelement <CODE>ch</CODE> from the input stream,then advance the current stream position, and return the element as<CODE>traits_type::<A HREF="string2.html#char_traits::to_int_type">to_int_type</A>(ch)</CODE>.It can do so in various ways:</P><UL><LI>If a <A HREF="#read position">read position</A> is available,it takes <CODE>ch</CODE> as the element stored in the read positionand advances the next pointer for the<A HREF="#input buffer">input buffer</A>.<LI>It can read an element directly, from some external source,and deliver it as the value <CODE>ch</CODE>.<LI>For a stream buffer with common input and output streams,it can make a read position available by writing out, to someexternal destination, some or all of the elementsbetween the beginning and next pointers for the output buffer.Or it can allocate new or additional storage for theinput buffer. The functionthen reads in, from some external source, one or more elements.</UL><P>If the function cannot succeed, it returns<CODE>traits_type::<A HREF="string2.html#char_traits::eof">eof</A>()</CODE>,or throws an exception. Otherwise,it returns the current element <CODE>ch</CODE> in the input stream,converted as described above, and advances the next pointerfor the input buffer. The default behavior is to call<CODE><A HREF="#streambuf::underflow">underflow</A>()</CODE>and, if that function returns <CODE>traits_type::eof()</CODE>,to return <CODE>traits_type::eof()</CODE>. Otherwise, the functionreturns the current element <CODE>ch</CODE> in the input stream,converted as described above, and advances the next pointerfor the input buffer.</P><H3><A NAME="streambuf::underflow"><CODE>streambuf::underflow</CODE></A></H3><PRE>virtual int_type <B>underflow</B>();</PRE><P>The protected virtual member function endeavors to extract the currentelement <CODE>ch</CODE> from the input stream,without advancing the current stream position, and return it as<CODE>traits_type::<A HREF="string2.html#char_traits::to_int_type">to_int_type</A>(ch)</CODE>.It can do so in various ways:</P><UL><LI>If a <A HREF="#read position">read position</A> is available,<CODE>ch</CODE> is the element stored in the read position.<LI>It can make a read position available by allocatingnew or additional storage for the<A HREF="#input buffer">input buffer</A>, then reading in,from some external source, one or more elements.</UL><P>If the function cannot succeed, it returns<CODE>traits_type::<A HREF="string2.html#char_traits::eof">eof</A>()</CODE>,or throws an exception. Otherwise,it returns the current element in the input stream,converted as described above.The default behavior is to return <CODE>traits_type::eof()</CODE>.</P><H3><A NAME="streambuf::xsgetn"><CODE>streambuf::xsgetn</CODE></A></H3><PRE>virtual streamsize <B>xsgetn</B>(char_type *ptr, streamsize count);</PRE><P>The protected virtual member function extracts up to <CODE>count</CODE>elements from the input stream, as if by repeated calls to<CODE><A HREF="#streambuf::sbumpc">sbumpc</A></CODE>,and stores them in the array beginning at <CODE>ptr</CODE>.It returns the number of elements actually extracted.</P><H3><A NAME="streambuf::xsputn"><CODE>streambuf::xsputn</CODE></A></H3><PRE>virtual streamsize <B>xsputn</B>(const char_type *ptr, streamsize count);</PRE><P>The protected virtual member function inserts up to <CODE>count</CODE>elements into the output stream, as if by repeated calls to<CODE><A HREF="#streambuf::sputc">sputc</A></CODE>,from the array beginning at <CODE>ptr</CODE>.It returns the number of elements actually inserted.</P><HR><P>See also the<B><A HREF="index.html#Table of Contents">Table of Contents</A></B> and the<B><A HREF="_index.html">Index</A></B>.</P><P><I><A HREF="crit_pjp.html">Copyright</A> © 1992-2002by P.J. Plauger. All rights reserved.</I></P><!--V4.01:1125--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -