⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fstream.html

📁 ST20 Embedded Toolset R2.0.5用于开发基于ST20芯片机顶盒软件的开发平台,2.0.5版本,国内找不到的.在国外论坛上花了N天才找到!
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<HTML><HEAD><TITLE>&lt;fstream&gt;</TITLE></HEAD><BODY><H1><A NAME="&lt;fstream&gt;"><CODE>&lt;fstream&gt;</CODE></A></H1><HR><P>Include the <A HREF="lib_cpp.html#iostreams">iostreams</A>standard header <B><CODE>&lt;fstream&gt;</CODE></B>to define several classes that supportiostreams operations onsequences stored in external<A HREF="lib_file.html#files">files</A>.</P><PRE>namespace std {template&lt;class Elem, class Tr = char_traits&lt;Elem&gt; &gt;    class <B><A HREF="#basic_filebuf">basic_filebuf</A></B>;typedef basic_filebuf&lt;char&gt; <B><A HREF="#filebuf">filebuf</A></B>;typedef basic_filebuf&lt;wchar_t&gt; <B><A HREF="#wfilebuf">wfilebuf</A></B>;template&lt;class Elem, class Tr = char_traits&lt;Elem&gt; &gt;    class <B><A HREF="#basic_ifstream">basic_ifstream</A></B>;typedef basic_ifstream&lt;char&gt; <B><A HREF="#ifstream">ifstream</A></B>;typedef basic_ifstream&lt;wchar_t&gt; <B><A HREF="#wifstream">wifstream</A></B>;template&lt;class Elem, class Tr = char_traits&lt;Elem&gt; &gt;    class <B><A HREF="#basic_ofstream">basic_ofstream</A></B>;typedef basic_ofstream&lt;char&gt; <B><A HREF="#ofstream">ofstream</A></B>;typedef basic_ofstream&lt;wchar_t&gt; <B><A HREF="#wofstream">wofstream</A></B>;template&lt;class Elem, class Tr = char_traits&lt;Elem&gt; &gt;    class <B><A HREF="#basic_fstream">basic_fstream</A></B>;typedef basic_fstream&lt;char&gt; <B><A HREF="#fstream">fstream</A></B>;typedef basic_fstream&lt;wchar_t&gt; <B><A HREF="#wfstream">wfstream</A></B>;    };</PRE><H2><A NAME="basic_filebuf"><CODE>basic_filebuf</CODE></A></H2><PRE>template &lt;class Elem, class Tr = char_traits&lt;Elem&gt; &gt;    class <B>basic_filebuf</B> : public basic_streambuf&lt;Elem, Tr&gt; {public:    typedef typename basic_streambuf&lt;Elem, Tr&gt;::char_type        char_type;    typedef typename basic_streambuf&lt;Elem, Tr&gt;::traits_type        traits_type;    typedef typename basic_streambuf&lt;Elem, Tr&gt;::int_type        int_type;    typedef typename basic_streambuf&lt;Elem, Tr&gt;::pos_type        pos_type;    typedef typename basic_streambuf&lt;Elem, Tr&gt;::off_type        off_type;    <B><A HREF="#basic_filebuf::basic_filebuf">basic_filebuf</A></B>();    bool <B><A HREF="#basic_filebuf::is_open">is_open</A></B>() const;    basic_filebuf *<B><A HREF="#basic_filebuf::open">open</A></B>(const char *filename,        ios_base::openmode mode);    basic_filebuf *<B><A HREF="#basic_filebuf::close">close</A></B>();protected:    virtual pos_type <B><A HREF="#basic_filebuf::seekoff">seekoff</A></B>(off_type off,        ios_base::seekdir way,        ios_base::openmode which =            ios_base::in | ios_base::out);    virtual pos_type <B><A HREF="#basic_filebuf::seekpos">seekpos</A></B>(pos_type pos,        ios_base::openmode which =            ios_base::in | ios_base::out);    virtual int_type <B><A HREF="#basic_filebuf::underflow">underflow</A></B>();    virtual int_type <B><A HREF="#basic_filebuf::pbackfail">pbackfail</A></B>(int_type meta =        traits_type::eof());    virtual int_type <B><A HREF="#basic_filebuf::overflow">overflow</A></B>(int_type meta =        traits_type::eof());    virtual int <B><A HREF="#basic_filebuf::sync">sync</A></B>();    virtual basic_streambuf&lt;Elem, Tr&gt;        *<B><A HREF="#basic_filebuf::setbuf">setbuf</A></B>(Elem *buffer, streamsize count);    };</PRE><P>The template classdescribes a <B><A HREF="streambu.html#stream buffer">stream buffer</A></B> that controlsthe transmission of elementsof type <CODE>Elem</CODE>, whose<A HREF="string2.html#character traits">character traits</A> are determined by theclass <CODE>Tr</CODE>,to and from a sequence of elements stored in an external<A HREF="lib_file.html#files">file</A>.</P><P>An object of class<CODE>basic_filebuf&lt;Elem, Tr&gt;</CODE> stores a<B><A NAME="file pointer">file pointer</A></B>, which designates the<CODE><A HREF="stdio.html#FILE">FILE</A></CODE> objectthat controls the <B><A HREF="lib_file.html#stream">stream</A></B>associated with an<A HREF="lib_file.html#file open">open</A> file.It also stores pointers to two<B><A HREF="#file conversion facet">file conversion facets</A></B>for use by the protected member functions<CODE><A HREF="#basic_filebuf::overflow">overflow</A></CODE> and<CODE><A HREF="#basic_filebuf::underflow">underflow</A></CODE>.</P><H3><A NAME="basic_filebuf::basic_filebuf"><CODE>basic_filebuf::basic_filebuf</CODE></A></H3><PRE><B>basic_filebuf</B>();</PRE><P>The constructor stores a null pointer in all the pointerscontrolling the<A HREF="streambu.html#input buffer">input buffer</A> and the<A HREF="streambu.html#output buffer">output buffer</A>. Italso stores a null pointer in the<A HREF="#file pointer">file pointer</A>.</P><H3><A NAME="basic_filebuf::char_type"><CODE>basic_filebuf::char_type</CODE></A></H3><PRE>typedef Elem <B>char_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Elem</CODE>.</P><H3><A NAME="basic_filebuf::close"><CODE>basic_filebuf::close</CODE></A></H3><PRE>basic_filebuf *<B>close</B>();</PRE><P>The member function returns a null pointer if the<A HREF="#file pointer">file pointer</A> <CODE>fp</CODE>is a null pointer. Otherwise, it calls<CODE><A HREF="stdio.html#fclose">fclose</A>(fp)</CODE>.If that function returns a nonzero value, the functionreturns a null pointer. Otherwise, it returns <CODE>this</CODE>to indicate that the file was successfully<A HREF="lib_file.html#file close">closed</A>.</P><P>For a wide stream,if any insertions have occured since the stream was opened, or since the lastcall to <CODE>streampos</CODE>, the function calls<CODE><A HREF="#basic_filebuf::overflow">overflow</A>()</CODE>.It also inserts any sequence needed to restore the<A HREF="charset.html#initial conversion state">initial conversion state</A>,by using the<A HREF="#file conversion facet">file conversion facet</A><CODE>fac</CODE> to call<CODE>fac.<A HREF="locale2.html#codecvt::unshift">unshift</A></CODE>as needed. Each element <CODE>byte</CODE> of type <I>char</I> thusproduced is written to the associated stream designated by thefile pointer <CODE>fp</CODE> as if by successive calls of the form<CODE><A HREF="stdio.html#fputc">fputc</A>(byte, fp)</CODE>.If the call to <CODE>fac.unshift</CODE> or any write fails,the function does not succeed.</P><H3><A NAME="basic_filebuf::int_type"><CODE>basic_filebuf::int_type</CODE></A></H3><PRE>typedef typename traits_type::int_type <B>int_type</B>;</PRE><P>The type is a synonym for<CODE>traits_type::<A HREF="string2.html#char_traits::int_type">int_type</A></CODE>.</P><H3><A NAME="basic_filebuf::is_open"><CODE>basic_filebuf::is_open</CODE></A></H3><PRE>bool <B>is_open</B>();</PRE><P>The member function returns true if the<A HREF="#file pointer">file pointer</A> is not a null pointer.</P><H3><A NAME="basic_filebuf::off_type"><CODE>basic_filebuf::off_type</CODE></A></H3><PRE>typedef typename traits_type::off_type <B>off_type</B>;</PRE><P>The type is a synonym for<CODE>traits_type::<A HREF="string2.html#char_traits::off_type">off_type</A></CODE>.</P><H3><A NAME="basic_filebuf::open"><CODE>basic_filebuf::open</CODE></A></H3><PRE>basic_filebuf *<B>open</B>(const char *filename,    ios_base::openmode mode);</PRE><P>The member function endeavors to open the file with<A HREF="lib_over.html#filename">filename</A> <CODE>filename</CODE>, by calling<CODE><A HREF="stdio.html#fopen">fopen</A>(filename, strmode)</CODE>. Here<CODE>strmode</CODE> is determined from <CODE>mode &amp;~(<A HREF="ios.html#ios_base::ate">ate</A> &amp; |<A HREF="ios.html#ios_base::binary">binary</A>)</CODE>:</P><UL><LI><CODE>ios_base::<A HREF="ios.html#ios_base::in">in</A></CODE>becomes <CODE>"r"</CODE> (open existing file for reading).</LI><LI><CODE>ios_base::<A HREF="ios.html#ios_base::out">out</A></CODE> or<CODE>ios_base::out |ios_base::<A HREF="ios.html#ios_base::trunc">trunc</A></CODE>becomes <CODE>"w"</CODE> (truncate existing file or create for writing).</LI><LI><CODE>ios_base::out |ios_base::<A HREF="ios.html#ios_base::app">app</A></CODE>becomes <CODE>"a"</CODE> (open existing file for appending all writes).</LI><LI><CODE>ios_base::in | ios_base::out</CODE>becomes <CODE>"r+"</CODE> (open existing file for reading and writing).</LI><LI><CODE>ios_base::in | ios_base::out |ios_base::trunc</CODE> becomes <CODE>"w+"</CODE>(truncate existing file or create for reading and writing).</LI><LI><CODE>ios_base::in | ios_base::out |ios_base::app</CODE> becomes <CODE>"a+"</CODE>(open existing file for reading and for appending all writes).</LI></UL><P>If <CODE>mode &amp; ios_base::binary</CODE> is nonzero,the function appends <CODE>b</CODE> to <CODE>strmode</CODE>to open a <A HREF="lib_file.html#binary stream">binary stream</A>instead of a <A HREF="lib_file.html#text stream">text stream</A>.It then stores the value returned by <CODE>fopen</CODE> in the<A HREF="#file pointer">file pointer</A> <CODE>fp</CODE>. If<CODE>mode &amp; ios_base::ate</CODE> is nonzero and thefile pointer is not a null pointer, the function calls<CODE><A HREF="stdio.html#fseek">fseek</A>(fp, 0,<A HREF="stdio.html#SEEK_END">SEEK_END</A>)</CODE> toposition the stream at end-of-file. If that positioning operationfails, the function calls<CODE><A HREF="#basic_filebuf::close">close</A>(fp)</CODE> andstores a null pointer in the file pointer.</P><P>If the file pointer is not a null pointer, the functiondetermines the<B><A NAME="file conversion facet">file conversion facet</A></B>:<CODE><A HREF="locale2.html#use_facet">use_facet</A>&lt;<A HREF="locale2.html#codecvt">codecvt</A>&lt;Elem, char,traits_type::<A HREF="string2.html#char_traits::state_type">state_type</A>&gt;&gt;(<A HREF="streambu.html#basic_streambuf::getloc">getloc</A>())</CODE>,for use by<CODE><A HREF="#basic_filebuf::underflow">underflow</A></CODE>and<CODE><A HREF="#basic_filebuf::overflow">overflow</A></CODE>.</P><P>If the file pointer is a null pointer, the function returnsa null pointer. Otherwise, it returns <CODE>this</CODE>.</P><H3><A NAME="basic_filebuf::overflow"><CODE>basic_filebuf::overflow</CODE></A></H3><PRE>virtual int_type <B>overflow</B>(int_type meta =    traits_type::eof());</PRE><P>If <CODE>meta !=traits_type::<A HREF="string2.html#char_traits::eof">eof</A>()</CODE>,the protected virtual member function endeavors to insert the element<CODE>ch = traits_type::<A HREF="string2.html#char_traits::to_char_type">to_char_type</A>(meta)</CODE>into the<A HREF="streambu.html#output buffer">output buffer</A>.It can do so in various ways:</P><UL><LI>If a <A HREF="streambu.html#write position">write position</A>is available, it can store the element into the write positionand increment the next pointer for the output buffer.</LI><LI>It can make a write position available by allocatingnew or additional storage for the output buffer.</LI><LI>It can convert any pending output in the output buffer, followedby <CODE>ch</CODE>, by using the<A HREF="#file conversion facet">file conversion facet</A><CODE>fac</CODE> to call<CODE>fac.<A HREF="locale2.html#codecvt::out">out</A></CODE>as needed. Each element <CODE>ch</CODE> of type <I>char</I> thusproduced is written to the associated stream designated by the<A HREF="#file pointer">file pointer</A> <CODE>fp</CODE>as if by successive calls of the form<CODE><A HREF="stdio.html#fputc">fputc</A>(ch, fp)</CODE>.If any conversion or write fails, the function does not succeed.</LI></UL><P>If the function cannot succeed, it returns <CODE>traits_type::eof()</CODE>.Otherwise, it returns<CODE>traits_type::<A HREF="string2.html#char_traits::not_eof">not_eof</A>(meta)</CODE>.</P><H3><A NAME="basic_filebuf::pbackfail"><CODE>basic_filebuf::pbackfail</CODE></A></H3><PRE>virtual int_type <B>pbackfail</B>(int_type meta =    traits_type::eof());</PRE>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -