📄 fstream.html
字号:
<H3><A NAME="basic_fstream::open"><CODE>basic_fstream::open</CODE></A></H3><PRE>void <B>open</B>(const char *filename, ios_base::openmode mode = ios_base::in | ios_base::out);</PRE><P>The member function calls<CODE><A HREF="#basic_fstream::rdbuf">rdbuf</A>()-><A HREF="#basic_filebuf::open">open</A>(filename, mode)</CODE>.If that function returns a null pointer, the function calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.</P><H3><A NAME="basic_fstream::rdbuf"><CODE>basic_fstream::rdbuf</CODE></A></H3><PRE>basic_filebuf<Elem, Tr> *<B>rdbuf</B>() const</PRE><P>The member function returns the address of the storedstream buffer, of type pointer to<CODE><A HREF="#basic_filebuf">basic_filebuf</A><Elem, Tr></CODE>.</P><H2><A NAME="basic_ifstream"><CODE>basic_ifstream</CODE></A></H2><PRE>template <class Elem, class Tr = char_traits<Elem> > class <B>basic_ifstream</B> : public basic_istream<Elem, Tr> {public: basic_filebuf<Elem, Tr> *<B><A HREF="#basic_ifstream::rdbuf">rdbuf</A></B>() const; <B><A HREF="#basic_ifstream::basic_ifstream">basic_ifstream</A></B>(); explicit <B><A HREF="#basic_ifstream::basic_ifstream">basic_ifstream</A></B>(const char *filename, ios_base::openmode mode = ios_base::in); bool <B><A HREF="#basic_ifstream::is_open">is_open</A></B>() const; void <B><A HREF="#basic_ifstream::open">open</A></B>(const char *filename, ios_base::openmode mode = ios_base::in); void <B><A HREF="#basic_ifstream::close">close</A></B>(); };</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_filebuf">basic_filebuf</A><Elem, Tr></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>. The object stores an object of class<CODE>basic_filebuf<Elem, Tr></CODE>.</P><H3><A NAME="basic_ifstream::basic_ifstream"><CODE>basic_ifstream::basic_ifstream</CODE></A></H3><PRE><B>basic_ifstream</B>();explicit <B>basic_ifstream</B>(const char *filename, 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_filebuf">basic_filebuf</A><Elem, Tr></CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#basic_filebuf::basic_filebuf">basic_filebuf</A><Elem,Tr>()</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_filebuf::basic_filebuf">basic_filebuf</A><Elem, Tr>()</CODE>,then <CODE>sb.<A HREF="#basic_filebuf::open">open</A>(filename, mode| ios_base::in)</CODE>. If the latter function returns a nullpointer, the constructor calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.</P><H3><A NAME="basic_ifstream::close"><CODE>basic_ifstream::close</CODE></A></H3><PRE>void <B>close</B>();</PRE><P>The member function calls<CODE><A HREF="#basic_ifstream::rdbuf">rdbuf</A>()-><A HREF="#basic_filebuf::close">close</A>()</CODE>.</P><H3><A NAME="basic_ifstream::is_open"><CODE>basic_ifstream::is_open</CODE></A></H3><PRE>bool <B>is_open</B>();</PRE><P>The member function returns<CODE><A HREF="#basic_ifstream::rdbuf">rdbuf</A>()-><A HREF="#basic_filebuf::is_open">is_open</A>()</CODE>.</P><H3><A NAME="basic_ifstream::open"><CODE>basic_ifstream::open</CODE></A></H3><PRE>void <B>open</B>(const char *filename, ios_base::openmode mode = ios_base::in);</PRE><P>The member function calls<CODE><A HREF="#basic_ifstream::rdbuf">rdbuf</A>()-><A HREF="#basic_filebuf::open">open</A>(filename, mode | ios_base::in)</CODE>.If that function returns a null pointer, the function calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.</P><H3><A NAME="basic_ifstream::rdbuf"><CODE>basic_ifstream::rdbuf</CODE></A></H3><PRE>basic_filebuf<Elem, Tr> *<B>rdbuf</B>() const</PRE><P>The member function returns the address of the stored stream buffer.</P><H2><A NAME="basic_ofstream"><CODE>basic_ofstream</CODE></A></H2><PRE>template <class Elem, class Tr = char_traits<Elem> > class <B>basic_ofstream</B> : public basic_ostream<Elem, Tr> {public: basic_filebuf<Elem, Tr> *<B><A HREF="#basic_ofstream::rdbuf">rdbuf</A></B>() const; <B><A HREF="#basic_ofstream::basic_ofstream">basic_ofstream</A></B>(); explicit <B><A HREF="#basic_ofstream::basic_ofstream">basic_ofstream</A></B>(const char *filename, ios_base::openmode mode = ios_base::out); bool <B><A HREF="#basic_ofstream::is_open">is_open</A></B>() const; void <B><A HREF="#basic_ofstream::open">open</A></B>(const char *filename, ios_base::openmode mode = ios_base::out); void <B><A HREF="#basic_ofstream::close">close</A></B>(); };</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_filebuf">basic_filebuf</A><Elem, Tr></CODE>,with elements of type <CODE>Ele</CODE>, whose<A HREF="string2.html#character traits">character traits</A> are determinedby the class <CODE>Tr</CODE>. The object stores an object of class<CODE>basic_filebuf<Elem, Tr></CODE>.</P><H3><A NAME="basic_ofstream::basic_ofstream"><CODE>basic_ofstream::basic_ofstream</CODE></A></H3><PRE><B>basic_ofstream</B>();explicit <B>basic_ofstream</B>(const char *filename, ios_base::openmode which = 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_filebuf">basic_filebuf</A><Elem, Tr></CODE>.It also initializes <CODE>sb</CODE> by calling<CODE><A HREF="#basic_filebuf::basic_filebuf">basic_filebuf</A><Elem, Tr>()</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_filebuf::basic_filebuf">basic_filebuf</A><Elem, Tr>()</CODE>,then <CODE>sb.<A HREF="#basic_filebuf::open">open</A>(filename, mode| ios_base::out)</CODE>. If the latter function returns a nullpointer, the constructor calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.</P><H3><A NAME="basic_ofstream::close"><CODE>basic_ofstream::close</CODE></A></H3><PRE>void <B>close</B>();</PRE><P>The member function calls<CODE><A HREF="#basic_ofstream::rdbuf">rdbuf</A>()-><A HREF="#basic_filebuf::close">close</A>()</CODE>.</P><H3><A NAME="basic_ofstream::is_open"><CODE>basic_ofstream::is_open</CODE></A></H3><PRE>bool <B>is_open</B>();</PRE><P>The member function returns<CODE><A HREF="#basic_ofstream::rdbuf">rdbuf</A>()-><A HREF="#basic_filebuf::is_open">is_open</A>()</CODE>.</P><H3><A NAME="basic_ofstream::open"><CODE>basic_ofstream::open</CODE></A></H3><PRE>void <B>open</B>(const char *filename, ios_base::openmode mode = ios_base::out);</PRE><P>The member function calls<CODE><A HREF="#basic_ofstream::rdbuf">rdbuf</A>()-><A HREF="#basic_filebuf::open">open</A>(filename, mode | ios_base::out)</CODE>.If that function returns a null pointer, the function calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.</P><H3><A NAME="basic_ofstream::rdbuf"><CODE>basic_ofstream::rdbuf</CODE></A></H3><PRE>basic_filebuf<Elem, Tr> *<B>rdbuf</B>() const</PRE><P>The member function returns the address of the storedstream buffer.</P><H2><A NAME="filebuf"><CODE>filebuf</CODE></A></H2><PRE>typedef basic_filebuf<char, char_traits<char> > <B>filebuf</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_filebuf"><CODE>basic_filebuf</CODE></A>, specializedfor elements of type <I>char</I> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="fstream"><CODE>fstream</CODE></A></H2><PRE>typedef basic_fstream<char, char_traits<char> > <B>fstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_fstream"><CODE>basic_fstream</CODE></A>, specializedfor elements of type <I>char</I> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="ifstream"><CODE>ifstream</CODE></A></H2><PRE>typedef basic_ifstream<char, char_traits<char> > <B>ifstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_ifstream"><CODE>basic_ifstream</CODE></A>, specializedfor elements of type <I>char</I> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="ofstream"><CODE>ofstream</CODE></A></H2><PRE>typedef basic_ofstream<char, char_traits<char> > <B>ofstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_ofstream"><CODE>basic_ofstream</CODE></A>, specializedfor elements of type <I>char</I> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="wfstream"><CODE>wfstream</CODE></A></H2><PRE>typedef basic_fstream<wchar_t, char_traits<wchar_t> > <B>wfstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_fstream"><CODE>basic_fstream</CODE></A>, specializedfor elements of type <CODE>wchar_t</CODE> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="wifstream"><CODE>wifstream</CODE></A></H2><PRE>typedef basic_ifstream<wchar_t, char_traits<wchar_t> > <B>wifstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_ifstream"><CODE>basic_ifstream</CODE></A>, specializedfor elements of type <CODE>wchar_t</CODE> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="wofstream"><CODE>wofstream</CODE></A></H2><PRE>typedef basic_ofstream<wchar_t, char_traits<wchar_t> > <B>wofstream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_ofstream"><CODE>basic_ofstream</CODE></A>, specializedfor elements of type <CODE>wchar_t</CODE> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="wfilebuf"><CODE>wfilebuf</CODE></A></H2><PRE>typedef basic_filebuf<wchar_t, char_traits<wchar_t> > <B>wfilebuf</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_filebuf"><CODE>basic_filebuf</CODE></A>, specializedfor elements of type <CODE>wchar_t</CODE> with default<A HREF="string2.html#character traits">character traits</A>.</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 + -