📄 sstream.html
字号:
<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="basic_stringbuf::traits_type"><CODE>basic_stringbuf::traits_type</CODE></A></H3><PRE>typedef Tr <B>traits_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Tr</CODE>.</P><H3><A NAME="basic_stringbuf::underflow"><CODE>basic_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="basic_istringstream"><CODE>basic_istringstream</CODE></A></H2><PRE>template <class Elem, class Tr = char_traits<Elem>, class Alloc = allocator<Elem> > class <B>basic_istringstream</B> : public basic_istream<Elem, Tr> {public: typedef Alloc <B><A HREF="#basic_istringstream::allocator_type">allocator_type</A></B>; explicit <B><A HREF="#basic_istringstream::basic_istringstream">basic_istringstream</A></B>( ios_base::openmode mode = ios_base::in); explicit <B><A HREF="#basic_istringstream::basic_istringstream">basic_istringstream</A></B>( const basic_string<Elem, Tr, Alloc>& str, ios_base::openmode mode = ios_base::in); basic_stringbuf<Elem, Tr, Alloc> *<B><A HREF="#basic_istringstream::rdbuf">rdbuf</A></B>() const; basic_string<Elem, Tr, Alloc> <B><A HREF="#basic_istringstream::str">str</A></B>(); void <B><A HREF="#basic_istringstream::str">str</A></B>(const basic_string<Elem, Tr, Alloc>& newstr); };</PRE><P>The template 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="#basic_stringbuf">basic_stringbuf</A><Elem, Tr, Alloc></CODE>,with elements of type <CODE>Elem</CODE>, whose<A HREF="string2.html#character traits">character traits</A> are determinedby the class <CODE>Tr</CODE>, and whose elements are allocated byan allocator of class <CODE>Alloc</CODE>. The object stores an object of class<CODE>basic_stringbuf<Elem, Tr, Alloc></CODE>.</P><H3><A NAME="basic_istringstream::allocator_type"><CODE>basic_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="basic_istringstream::basic_istringstream"><CODE>basic_istringstream::basic_istringstream</CODE></A></H3><PRE>explicit <B>basic_istringstream</B>( ios_base::openmode mode = ios_base::in);explicit <B>basic_istringstream</B>( const basic_string<Elem, Tr, Alloc>& str, ios_base::openmode mode = ios_base::in);</PRE><P>The first constructor initializes the base class by calling<CODE><A HREF="istream.html#basic_istream::basic_istream">basic_istream</A>(sb)</CODE>,where <CODE>sb</CODE> is the stored object of class<CODE><A HREF="#basic_stringbuf">basic_stringbuf</A><Elem, Tr, Alloc></CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#basic_stringbuf::basic_stringbuf">basic_stringbuf</A><Elem,Tr, Alloc>(mode | ios_base::in)</CODE>.</P><P>The second constructor initializes the base class by calling<CODE>basic_istream(sb)</CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#basic_stringbuf::basic_stringbuf">basic_stringbuf</A><Elem,Tr, Alloc>(str, mode | ios_base::in)</CODE>.</P><H3><A NAME="basic_istringstream::rdbuf"><CODE>basic_istringstream::rdbuf</CODE></A></H3><PRE>basic_stringbuf<Elem, Tr, Alloc> *<B>rdbuf</B>() const</PRE><P>The member function returns the address of the storedstream buffer, of type pointer to<CODE><A HREF="#basic_stringbuf">basic_stringbuf</A><Elem,Tr, Alloc></CODE>.</P><H3><A NAME="basic_istringstream::str"><CODE>basic_istringstream::str</CODE></A></H3><PRE>basic_string<Elem, Tr, Alloc> <B>str</B>() const;void <B>str</B>(const basic_string<Elem, Tr, Alloc>& newstr);</PRE><P>The first member function returns<CODE><A HREF="#basic_istringstream::rdbuf">rdbuf</A>()-><A HREF="#basic_stringbuf::str">str</A>()</CODE>.The second member function calls <CODE>rdbuf()-> str(newstr)</CODE>.</P><H2><A NAME="basic_ostringstream"><CODE>basic_ostringstream</CODE></A></H2><PRE>template <class Elem, class Tr = char_traits<Elem>, class Alloc = allocator<Elem> > class <B>basic_ostringstream</B> : public basic_ostream<Elem, Tr> {public: explicit <B><A HREF="#basic_ostringstream::basic_ostringstream">basic_ostringstream</A></B>( ios_base::openmode mode = ios_base::out); explicit <B><A HREF="#basic_ostringstream::basic_ostringstream">basic_ostringstream</A></B>( const basic_string<Elem, Tr, Alloc>& str, ios_base::openmode mode = ios_base::out); basic_stringbuf<Elem, Tr, Alloc> *<B><A HREF="#basic_ostringstream::rdbuf">rdbuf</A></B>() const; basic_string<Elem, Tr, Alloc> <B><A HREF="#basic_ostringstream::str">str</A></B>(); void <B><A HREF="#basic_ostringstream::str">str</A></B>(const basic_string<Elem, Tr, Alloc>& newstr); };</PRE><P>The template 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="#basic_stringbuf">basic_stringbuf</A><Elem, Tr, Alloc></CODE>,with elements of type <CODE>Elem</CODE>, whose<A HREF="string2.html#character traits">character traits</A> are determinedby the class <CODE>Tr</CODE>, and whose elements are allocated byan allocator of class <CODE>Alloc</CODE>. The object stores an object of class<CODE>basic_stringbuf<Elem, Tr, Alloc></CODE>.</P><H3><A NAME="basic_ostringstream::allocator_type"><CODE>basic_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="basic_ostringstream::basic_ostringstream"><CODE>basic_ostringstream::basic_ostringstream</CODE></A></H3><PRE>explicit <B>basic_ostringstream</B>( ios_base::openmode mode = ios_base::out);explicit <B>basic_ostringstream</B>( const basic_string<Elem, Tr, Alloc>& str, ios_base::openmode mode = ios_base::out);</PRE><P>The first constructor initializes the base class by calling<CODE><A HREF="ostream.html#basic_ostream::basic_ostream">basic_ostream</A>(sb)</CODE>,where <CODE>sb</CODE> is the stored object of class<CODE><A HREF="#basic_stringbuf">basic_stringbuf</A><Elem, Tr, Alloc></CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#basic_stringbuf::basic_stringbuf">basic_stringbuf</A><Elem,Tr, Alloc>(mode | ios_base::out)</CODE>.</P><P>The second constructor initializes the base class by calling<CODE>basic_ostream(sb)</CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#basic_stringbuf::basic_stringbuf">basic_stringbuf</A><Elem,Tr, Alloc>(str, mode | ios_base::out)</CODE>.</P><H3><A NAME="basic_ostringstream::rdbuf"><CODE>basic_ostringstream::rdbuf</CODE></A></H3><PRE>basic_stringbuf<Elem, Tr, Alloc> *<B>rdbuf</B>() const</PRE><P>The member function returns the address of the storedstream buffer, of type pointer to<CODE><A HREF="#basic_stringbuf">basic_stringbuf</A><Elem,Tr, Alloc></CODE>.</P><H3><A NAME="basic_ostringstream::str"><CODE>basic_ostringstream::str</CODE></A></H3><PRE>basic_string<Elem, Tr, Alloc> <B>str</B>() const;void <B>str</B>(const basic_string<Elem, Tr, Alloc>& newstr);</PRE><P>The first member function returns<CODE><A HREF="#basic_ostringstream::rdbuf">rdbuf</A>()-><A HREF="#basic_stringbuf::str">str</A>()</CODE>.The second member function calls <CODE>rdbuf()-> str(newstr)</CODE>.</P><H2><A NAME="basic_stringstream"><CODE>basic_stringstream</CODE></A></H2><PRE>template <class Elem, class Tr = char_traits<Elem>, class Alloc = allocator<Elem> > class <B>basic_stringstream</B> : public basic_iostream<Elem, Tr> {public: typedef Alloc <B><A HREF="#basic_stringstream::allocator_type">allocator_type</A></B>; explicit <B><A HREF="#basic_stringstream::basic_stringstream">basic_stringstream</A></B>( ios_base::openmode mode = ios_base::in | ios_base::out); explicit <B><A HREF="#basic_stringstream::basic_stringstream">basic_stringstream</A></B>( const basic_string<Elem, Tr, Alloc>& str, ios_base::openmode mode = ios_base::in | ios_base::out); basic_stringbuf<Elem, Tr, Alloc> *<B><A HREF="#basic_stringstream::rdbuf">rdbuf</A></B>() const; basic_string<Elem, Tr, Alloc> <B><A HREF="#basic_stringstream::str">str</A></B>(); void <B><A HREF="#basic_stringstream::str">str</A></B>(const basic_string<Elem, Tr, Alloc>& newstr); };</PRE><P>The template class describes an object that controlsinsertion and extraction of elements and encoded objects using a<A HREF="streambu.html#stream buffer">stream buffer</A> of class<CODE><A HREF="#basic_stringbuf">basic_stringbuf</A><Elem, Tr, Alloc></CODE>,with elements of type <CODE>Elem</CODE>, whose<A HREF="string2.html#character traits">character traits</A> are determinedby the class <CODE>Tr</CODE>, and whose elements are allocated byan allocator of class <CODE>Alloc</CODE>. The object stores an object of class<CODE>basic_stringbuf<Elem, Tr, Alloc></CODE>.</P><H3><A NAME="basic_stringstream::allocator_type"><CODE>basic_stringstream::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="basic_stringstream::basic_stringstream"><CODE>basic_stringstream::basic_stringstream</CODE></A></H3><PRE>explicit <B>basic_stringstream</B>( ios_base::openmode mode = ios_base::in | ios_base::out);explicit <B>basic_stringstream</B>( const basic_string<Elem, Tr, Alloc>& str, ios_base::openmode mode = ios_base::in | ios_base::out);</PRE><P>The first constructor initializes the base class by calling<CODE><A HREF="istream.html#basic_iostream">basic_iostream</A>(sb)</CODE>,where <CODE>sb</CODE> is the stored object of class<CODE><A HREF="#basic_stringbuf">basic_stringbuf</A><Elem, Tr, Alloc></CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#basic_stringbuf::basic_stringbuf">basic_stringbuf</A><Elem,Tr, Alloc>(mode)</CODE>.</P><P>The second constructor initializes the base class by calling<CODE>basic_iostream(sb)</CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#basic_stringbuf::basic_stringbuf">basic_stringbuf</A><Elem,Tr, Alloc>(str, mode)</CODE>.</P><H3><A NAME="basic_stringstream::rdbuf"><CODE>basic_stringstream::rdbuf</CODE></A></H3><PRE>basic_stringbuf<Elem, Tr, Alloc> *<B>rdbuf</B>() const</PRE><P>The member function returns the address of the storedstream buffer, of type pointer to<CODE><A HREF="#basic_stringbuf">basic_stringbuf</A><Elem,Tr, Alloc></CODE>.</P><H3><A NAME="basic_stringstream::str"><CODE>basic_stringstream::str</CODE></A></H3><PRE>basic_string<Elem, Tr, Alloc> <B>str</B>() const;void <B>str</B>(const basic_string<Elem, Tr, Alloc>& newstr);</PRE><P>The first member function returns<CODE><A HREF="#basic_stringstream::rdbuf">rdbuf</A>()-><A HREF="#basic_stringbuf::str">str</A>()</CODE>.The second member function calls <CODE>rdbuf()-> str(newstr)</CODE>.</P><H2><A NAME="istringstream"><CODE>istringstream</CODE></A></H2><PRE>typedef basic_istringstream<char> <B>istringstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_istringstream"><CODE>basic_istringstream</CODE></A>, specializedfor elements of type <I>char.</I></P><H2><A NAME="ostringstream"><CODE>ostringstream</CODE></A></H2><PRE>typedef basic_ostringstream<char> <B>ostringstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_ostringstream"><CODE>basic_ostringstream</CODE></A>, specializedfor elements of type <I>char.</I></P><H2><A NAME="stringbuf"><CODE>stringbuf</CODE></A></H2><PRE>typedef basic_stringbuf<char> <B>stringbuf</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_stringbuf"><CODE>basic_stringbuf</CODE></A>, specializedfor elements of type <I>char.</I></P><H2><A NAME="stringstream"><CODE>stringstream</CODE></A></H2><PRE>typedef basic_stringstream<char> <B>stringstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_stringstream"><CODE>basic_stringstream</CODE></A>, specializedfor elements of type <I>char.</I></P><H2><A NAME="wistringstream"><CODE>wistringstream</CODE></A></H2><PRE>typedef basic_istringstream<wchar_t> <B>wistringstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_istringstream"><CODE>basic_istringstream</CODE></A>, specializedfor elements of type <CODE>wchar_t</CODE>.</P><H2><A NAME="wostringstream"><CODE>wostringstream</CODE></A></H2><PRE>typedef basic_ostringstream<wchar_t> <B>wostringstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_ostringstream"><CODE>basic_ostringstream</CODE></A>, specializedfor elements of type <CODE>wchar_t</CODE>.</P><H2><A NAME="wstringbuf"><CODE>wstringbuf</CODE></A></H2><PRE>typedef basic_stringbuf<wchar_t> <B>wstringbuf</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_stringbuf"><CODE>basic_stringbuf</CODE></A>, specializedfor elements of type <CODE>wchar_t</CODE>.</P><H2><A NAME="wstringstream"><CODE>wstringstream</CODE></A></H2><PRE>typedef basic_stringstream<wchar_t> <B>wstringstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_stringstream"><CODE>basic_stringstream</CODE></A>, specializedfor elements of type <CODE>wchar_t</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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -