sstream.html
来自「ST20 Embedded Toolset R2.0.5用于开发基于ST20芯片」· HTML 代码 · 共 482 行 · 第 1/2 页
HTML
482 行
Otherwise, it fails and returns an invalid stream position.</P><H3><A NAME="stringbuf::seekpos"><CODE>stringbuf::seekpos</CODE></A></H3><PRE>virtual pos_type <B>seekpos</B>(pos_type sp, ios_base::openmode mode = ios_base::in | ios_base::out);</PRE><P>The protected virtual member function endeavors to alter the currentpositions for the controlled streams. For an object of class<CODE>stringbuf</CODE>,a stream position consistspurely of a stream offset. Offset zero designates the first elementof the controlled sequence. The new position is determinedby <CODE>sp</CODE>.</P><P>If<CODE>mode & ios_base::in</CODE> is nonzero,the function alters the next position to read in the<A HREF="streambu.html#input buffer">input buffer</A>.If <CODE>mode & ios_base::out</CODE> is nonzero,the function alters the next position to write in the<A HREF="streambu.html#output buffer">output buffer</A>.For a stream to be affected, its buffer must exist.For a positioning operation to succeed, the resultingstream position must lie within the controlled sequence.Otherwise (or if neither position is affected) the positioningoperation fails.</P><P>If the function succeeds in altering either or both of the stream positions,it returns the resultant stream position.Otherwise, it fails and returns an invalid stream position.</P><H3><A NAME="stringbuf::str"><CODE>stringbuf::str</CODE></A></H3><PRE>string <B>str</B>() const;void <B>str</B>(const string& newstr);</PRE><P>The first member function returns an object of class<CODE><A HREF="string2.html#string">string</A></CODE>,whose controlled sequence is a copy of the sequence controlledby <CODE>*this</CODE>. The sequence copied depends on the stored<A HREF="#stringbuf mode">stringbuf mode</A> <CODE>mode</CODE>:</P><UL><LI>If <CODE>mode &ios_base::<A HREF="ios.html#ios_base::out">out</A></CODE> is nonzeroand an <A HREF="streambu.html#output buffer">output buffer</A> exists,the sequence is the entire output buffer(<CODE><A HREF="streambu.html#streambuf::epptr">epptr</A>() -<A HREF="streambu.html#streambuf::pbase">pbase</A>()</CODE>elements beginning with <CODE>pbase()</CODE>).</LI><LI>Otherwise, if <CODE>mode &ios_base::<A HREF="ios.html#ios_base::in">in</A></CODE> is nonzeroand an <A HREF="streambu.html#input buffer">input buffer</A> exists,the sequence is the entire input buffer(<CODE><A HREF="streambu.html#streambuf::egptr">egptr</A>() -<A HREF="streambu.html#streambuf::eback">eback</A>()</CODE>elements beginning with <CODE>eback()</CODE>).</LI><LI>Otherwise, the copied sequence is empty.</LI></UL><P>The second member function deallocates any sequence currentlycontrolled by <CODE>*this</CODE>. It thenallocates a copy of the sequence controlledby <CODE>newstr</CODE>. If <CODE>mode & ios_base::in</CODE> is nonzero,it sets the input buffer to begin readingat the beginning of the sequence.If <CODE>mode & ios_base::out</CODE> is nonzero,it sets the output buffer to beginwriting at the beginning of the sequence.</P><H3><A NAME="stringbuf::traits_type"><CODE>stringbuf::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="stringbuf::underflow"><CODE>stringbuf::underflow</CODE></A></H3><PRE>virtual int_type <B>underflow</B>();</PRE><P>The protected virtual member function endeavors to extract the currentelement <CODE>byte</CODE> from the<A HREF="streambu.html#input buffer">input buffer</A>,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>(byte)</CODE>.It can do so in only one way:If a <A HREF="streambu.html#read position">read position</A>is available, it takes <CODE>byte</CODE> as the element storedin the read position and advances the next pointer for the input buffer.</P><P>If the function cannot succeed, it returns<CODE>traits_type::<A HREF="string2.html#char_traits::eof">eof</A>()</CODE>. Otherwise,it returns the current element in the input stream,converted as described above.</P><H2><A NAME="istringstream"><CODE>istringstream</CODE></A></H2><PRE>class <B>istringstream</B> : public istream {public: explicit <B><A HREF="#istringstream::istringstream">istringstream</A></B>(ios_base::openmode mode = ios_base::in); explicit <B><A HREF="#istringstream::istringstream">istringstream</A></B>(const string& str, ios_base::openmode mode = ios_base::in); stringbuf *<B><A HREF="#istringstream::rdbuf">rdbuf</A></B>() const; string <B><A HREF="#istringstream::str">str</A></B>(); void <B><A HREF="#istringstream::str">str</A></B>(const string& newstr); };</PRE><P>The class describes an object that controlsextraction of elements and encoded objects from a<A HREF="streambu.html#stream buffer">stream buffer</A> of class<CODE><A HREF="#stringbuf">stringbuf</A></CODE>.The object stores an object of class<CODE>stringbuf</CODE>.</P><H3><A NAME="istringstream::allocator_type"><CODE>istringstream::allocator_type</CODE></A></H3><PRE>typedef Alloc <B>allocator_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Alloc</CODE>.</P><H3><A NAME="istringstream::istringstream"><CODE>istringstream::istringstream</CODE></A></H3><PRE>explicit <B>istringstream</B>(ios_base::openmode mode = ios_base::in);explicit <B>istringstream</B>(const string& str, ios_base::openmode mode = ios_base::in);</PRE><P>The first constructor initializes the base class by calling<CODE><A HREF="istream.html#istream::istream">istream</A>(sb)</CODE>,where <CODE>sb</CODE> is the stored object of class<CODE><A HREF="#stringbuf">stringbuf</A></CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#stringbuf::stringbuf">stringbuf</A>(mode | ios_base::in)</CODE>.</P><P>The second constructor initializes the base class by calling<CODE>istream(sb)</CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#stringbuf::stringbuf">stringbuf</A>(str,mode | ios_base::in)</CODE>.</P><H3><A NAME="istringstream::rdbuf"><CODE>istringstream::rdbuf</CODE></A></H3><PRE>stringbuf *<B>rdbuf</B>() const</PRE><P>The member function returns the address of the storedstream buffer, of type pointer to<CODE><A HREF="#stringbuf">stringbuf</A></CODE>.</P><H3><A NAME="istringstream::str"><CODE>istringstream::str</CODE></A></H3><PRE>string <B>str</B>() const;void <B>str</B>(const string& newstr);</PRE><P>The first member function returns<CODE><A HREF="#istringstream::rdbuf">rdbuf</A>()-><A HREF="#stringbuf::str">str</A>()</CODE>.The second member function calls <CODE>rdbuf()-> str(newstr)</CODE>.</P><H2><A NAME="ostringstream"><CODE>ostringstream</CODE></A></H2><PRE>class <B>ostringstream</B> : public ostream {public: typedef Alloc <B><A HREF="#ostringstream::allocator_type">allocator_type</A></B>; explicit <B><A HREF="#ostringstream::ostringstream">ostringstream</A></B>(ios_base::openmode mode = ios_base::out); explicit <B><A HREF="#ostringstream::ostringstream">ostringstream</A></B>(const string& str, ios_base::openmode mode = ios_base::out); stringbuf *<B><A HREF="#ostringstream::rdbuf">rdbuf</A></B>() const; string <B><A HREF="#ostringstream::str">str</A></B>(); void <B><A HREF="#ostringstream::str">str</A></B>(const string& newstr); };</PRE><P>The class describes an object that controlsinsertion of elements and encoded objects into a<A HREF="streambu.html#stream buffer">stream buffer</A> of class<CODE><A HREF="#stringbuf">stringbuf</A></CODE>.The object stores an object of class<CODE>stringbuf</CODE>.</P><H3><A NAME="ostringstream::allocator_type"><CODE>ostringstream::allocator_type</CODE></A></H3><PRE>typedef Alloc <B>allocator_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Alloc</CODE>.</P><H3><A NAME="ostringstream::ostringstream"><CODE>ostringstream::ostringstream</CODE></A></H3><PRE>explicit <B>ostringstream</B>(ios_base::openmode mode = ios_base::out);explicit <B>ostringstream</B>(const string& str, ios_base::openmode mode = ios_base::out);</PRE><P>The first constructor initializes the base class by calling<CODE><A HREF="ostream.html#ostream::ostream">ostream</A>(sb)</CODE>,where <CODE>sb</CODE> is the stored object of class<CODE><A HREF="#stringbuf">stringbuf</A></CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#stringbuf::stringbuf">stringbuf</A>(mode | ios_base::out)</CODE>.</P><P>The second constructor initializes the base class by calling<CODE>ostream(sb)</CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#stringbuf::stringbuf">stringbuf</A>(str,mode | ios_base::out)</CODE>.</P><H3><A NAME="ostringstream::rdbuf"><CODE>ostringstream::rdbuf</CODE></A></H3><PRE>stringbuf *<B>rdbuf</B>() const</PRE><P>The member function returns the address of the storedstream buffer, of type pointer to<CODE><A HREF="#stringbuf">stringbuf</A></CODE>.</P><H3><A NAME="ostringstream::str"><CODE>ostringstream::str</CODE></A></H3><PRE>string <B>str</B>() const;void <B>str</B>(const string& newstr);</PRE><P>The first member function returns<CODE><A HREF="#ostringstream::rdbuf">rdbuf</A>()-><A HREF="#stringbuf::str">str</A>()</CODE>.The second member function calls <CODE>rdbuf()-> str(newstr)</CODE>.</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 + =
减小字号Ctrl + -
显示快捷键?