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

📄 ostream.html

📁 ST20 Embedded Toolset R2.0.5用于开发基于ST20芯片机顶盒软件的开发平台,2.0.5版本,国内找不到的.在国外论坛上花了N天才找到!
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML><HEAD><TITLE>&lt;ostream&gt;</TITLE></HEAD><BODY><H1><A NAME="&lt;ostream&gt;"><CODE>&lt;ostream&gt;</CODE></A></H1><HR><PRE>        // DECLARATIONSclass <B><A HREF="#ostream">ostream</A></B>;        // INSERTERSostream&amp;    <B><A HREF="#operator&lt;&lt;">operator&lt;&lt;</A></B>(ostream&amp; ostr, const char *str);ostream&amp;    <B><A HREF="#operator&lt;&lt;">operator&lt;&lt;</A></B>(ostream&amp; ostr, char ch);ostream&amp;    <B><A HREF="#operator&lt;&lt;">operator&lt;&lt;</A></B>(ostream&amp; ostr, const signed char *str);ostream&amp;    <B><A HREF="#operator&lt;&lt;">operator&lt;&lt;</A></B>(ostream&amp; ostr, signed char ch);ostream&amp;    <B><A HREF="#operator&lt;&lt;">operator&lt;&lt;</A></B>(ostream&amp; ostr, const unsigned char *str);ostream&amp;    <B><A HREF="#operator&lt;&lt;">operator&lt;&lt;</A></B>(ostream&amp; ostr, unsigned char ch);        // MANIPULATORSostream&amp; <B><A HREF="#endl">endl</A></B>(ostream&amp; ostr);ostream&amp; <B><A HREF="#ends">ends</A></B>(ostream&amp; ostr);ostream&amp; <B><A HREF="#flush">flush</A></B>(ostream&amp; ostr);        // END OF DECLARATIONS</PRE><P>Include the <A HREF="lib_cpp.html#iostreams">iostreams</A>standard header <B><CODE>&lt;ostream&gt;</CODE></B> to defineclass <CODE><A HREF="#ostream">ostream</A></CODE>,which mediates insertions for the iostreams.The header also defines several related<A HREF="ios.html#manipulators">manipulators</A>.(This header is typically included for you by anotherof the iostreams headers. You seldom have occasion to include itdirectly.)</P><H2><A NAME="ostream"><CODE>ostream</CODE></A></H2><HR><P><B><CODE><A HREF="#ostream::ostream">ostream</A>&#183; <A HREF="#ostream::flush">flush</A>&#183; <A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A>&#183; <A HREF="#ostream::put">put</A>&#183; <A HREF="#ostream::seekp">seekp</A>&#183; <A HREF="#ostream::sentry">sentry</A>&#183; <A HREF="#ostream::tellp">tellp</A>&#183; <A HREF="#ostream::write">write</A></CODE></B></P><HR><PRE>class <B>ostream</B> : public ios {public:    explicit <B><A HREF="#ostream::ostream">ostream</A></B>(streambuf *strbuf);    class <B><A HREF="#ostream::sentry">sentry</A></B>;    virtual <B>~ostream</B>();    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(        ostream&amp; (*pfn)(ostream&amp;));    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(        ios_base;&amp; (*pfn)(ios_base&amp;));    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(        ios&amp; (*pfn)(ios&amp;));    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(        streambuf *strbuf);    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(bool val);    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(short val);    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(unsigned short val);    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(int val);    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(unsigned int val);    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(long val);    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(unsigned long val);    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(float val);    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(double val);    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(long double val);    ostream&amp; <B><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></B>(const void *val);    ostream&amp; <B><A HREF="#ostream::put">put</A></B>(char_type ch);    ostream&amp; <B><A HREF="#ostream::write">write</A></B>(char_type *str, streamsize count);    ostream&amp; <B><A HREF="#ostream::flush">flush</A></B>();    pos_type <B><A HREF="#ostream::tellp">tellp</A></B>();    ostream&amp; <B><A HREF="#ostream::seekp">seekp</A></B>(pos_type pos);    ostream&amp; <B><A HREF="#ostream::seekp">seekp</A></B>(off_type off,        ios_base::seek_dir way);    };</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>with elements of type <I>char,</I> also known as<CODE><A HREF="ios.html#ios::char_type">char_type</A></CODE>, whose<A HREF="string2.html#character traits">character traits</A> are determined by theclass <CODE><A HREF="string2.html#char_traits">char_traits</A></CODE>,also known as<CODE><A HREF="ios.html#ios::traits_type">traits_type</A></CODE>.</P><P>Most of the member functions that overload<CODE><A HREF="#ostream::operator&lt;&lt;">operator&lt;&lt;</A></CODE>are <B><A NAME="formatted output functions">formatted output functions</A></B>.They follow the pattern:</P><PRE>    iostate state = goodbit;    const sentry ok(*this);    if (ok)        {try            {&lt;convert and insert elements            accumulate flags in state&gt; }        catch (...)            {try                {setstate(badbit); }            catch (...)                {}            if ((exceptions() &amp; badbit) != 0)                throw; }}    width(0);    // except for operator&lt;&lt;(Elem)    setstate(state);    return (*this);</PRE><P>Two other member functions are<B><A NAME="unformatted output functions">unformatted output functions</A></B>.They follow the pattern:</P><PRE>    iostate state = goodbit;    const sentry ok(*this);    if (!ok)        state |= badbit;    else        {try            {&lt;obtain and insert elements            accumulate flags in state&gt; }        catch (...)            {try                {setstate(badbit); }            catch (...)                {}            if ((exceptions() &amp; badbit) != 0)                throw; }}    setstate(state);    return (*this);</PRE><P>Both groups of functions call<CODE><A HREF="ios.html#ios::setstate">setstate</A>(badbit)</CODE>if they encounter a failure while inserting elements.</P><P>An object of class <CODE>ostream</CODE> stores onlya public base object of class<B><CODE><A HREF="ios.html#ios">ios</A></CODE></B></P><H3><A NAME="ostream::ostream"><CODE>ostream::ostream</CODE></A></H3><PRE>explicit <B>ostream</B>(streambuf *strbuf);</PRE><P>The constructor initializes the base class by calling<CODE><A HREF="ios.html#ios::init">init</A>(strbuf)</CODE>.</P><H3><A NAME="ostream::flush"><CODE>ostream::flush</CODE></A></H3><PRE>ostream&amp; <B>flush</B>();</PRE><P>If <CODE><A HREF="ios.html#ios::rdbuf">rdbuf</A>()</CODE> isnot a null pointer, the function calls<CODE>rdbuf()-&gt;<A HREF="streambu.html#streambuf::pubsync">pubsync</A>()</CODE>.If that returns -1, the function calls<CODE><A HREF="ios.html#ios::setstate">setstate</A>(badbit)</CODE>.It returns <CODE>*this</CODE>.</P><H3><A NAME="ostream::operator&lt;&lt;"><CODE>ostream::operator&lt;&lt;</CODE></A></H3><PRE>ostream&amp; <B>operator&lt;&lt;</B>(    ostream&amp; (*pfn)(ostream&amp;));ostream&amp; <B>operator&lt;&lt;</B>(    ios_base&amp; (*pfn)(ios_base&amp;));ostream&amp; <B>operator&lt;&lt;</B>(    ios&amp; (*pfn)(ios&amp;));ostream&amp; <B>operator&lt;&lt;</B>(    streambuf *strbuf);ostream&amp; <B>operator&lt;&lt;</B>(bool val);ostream&amp; <B>operator&lt;&lt;</B>(short val);ostream&amp; <B>operator&lt;&lt;</B>(unsigned short val);ostream&amp; <B>operator&lt;&lt;</B>(int val);ostream&amp; <B>operator&lt;&lt;</B>(unsigned int val);ostream&amp; <B>operator&lt;&lt;</B>(long val);ostream&amp; <B>operator&lt;&lt;</B>(unsigned long val);ostream&amp; <B>operator&lt;&lt;</B>(float val);ostream&amp; <B>operator&lt;&lt;</B>(double val);ostream&amp; <B>operator&lt;&lt;</B>(long double val);ostream&amp; <B>operator&lt;&lt;</B>(const void *val);</PRE><P>The first member function ensures that an expression of theform <CODE>ostr &lt;&lt; endl</CODE> calls<CODE><A HREF="#endl">endl</A>(ostr)</CODE>, then returns <CODE>*this</CODE>.The second and third functions ensure that other<A HREF="ios.html#manipulators">manipulators</A>,such as <CODE><A HREF="ios.html#hex">hex</A></CODE> behavesimilarly. The remaining functions are all<A HREF="#formatted output functions">formatted output functions</A>.</P><P>The function:</P><PRE>ostream&amp; <B>operator&lt;&lt;</B>(    streambuf *strbuf);</PRE><P>extracts elements from <CODE>strbuf</CODE>,if <CODE>strbuf</CODE> is not a null pointer, and inserts them.If <CODE>strbuf</CODE> is a null pointer, the function calls<CODE><A HREF="ios.html#ios::setstate">setstate</A>(badbit)</CODE>.Otherwise, extraction stops on end-of-file,or if an extraction throws an exception (which is rethrown).It also stops, without extracting the element in question,if an insertion fails. If the function inserts no elements, orif an extraction throws an exception, the function calls<CODE><A HREF="ios.html#ios::setstate">setstate</A>(failbit)</CODE>.In any case, the function returns <CODE>*this</CODE>.</P><P>All the remaining functions generate an output field and insert it.The output output field is generated by the same rules used by the<A HREF="lib_prin.html#Print Functions">print functions</A>for generating a series of <I>char</I> elements to a file.Where a print function pads a field with either spaces or the digit<CODE>0</CODE>, however, the function instead uses<CODE><A HREF="ios.html#ios::fill">fill</A></CODE>.The equivalent<A HREF="lib_prin.html#print conversion specification">print conversionspecification</A> is determined as described for each function below.</P><P><B><A NAME="padding">Padding</A></B> occurs only ifthe minimum number of elements <CODE>N</CODE> required tospecify the output field is less than<CODE><A HREF="ios.html#ios_base::width">width</A>()</CODE>.Such padding consists of a sequence of <CODE>N - width()</CODE> copies of<CODE>fill()</CODE>.Padding then occurs as follows:</P><UL><LI>If <CODE><A HREF="ios.html#ios_base::flags">flags</A>() &amp;ios_base::<A HREF="ios.html#ios_base::adjustfield">adjustfield</A> ==ios_base::<A HREF="ios.html#ios_base::left">left</A></CODE>,the flag <CODE>-</CODE> is prepended to the conversion specification.(Padding occurs after the generated text.)</LI><LI>If <CODE>flags() &amp; ios_base::adjustfield ==ios_base::<A HREF="ios.html#ios_base::internal">internal</A></CODE>,the flag <CODE>0</CODE> is prepended. (For a numeric output field,padding occurs where the print functions pad with <CODE>0</CODE>.)</LI><LI>Otherwise, no additional flag is prepended.(Padding occurs before the generated sequence.)</UL><P>The function:</P><PRE>ostream&amp; <B>operator&lt;&lt;</B>(bool val);</PRE><P>converts <CODE>val</CODE> to a<B><A NAME="boolean output field">boolean output field</A></B>and inserts it as an array of <I>char,</I> witha conversion specifier of <CODE>s</CODE>.</P><P>A boolean output field takes one of two forms.If <CODE><A HREF="ios.html#ios_base::flags">flags</A>() &amp;ios_base::<A HREF="ios.html#ios_base::boolalpha">boolalpha</A></CODE>is false, the generated sequence is either <CODE>0</CODE> (for false)or <CODE>1</CODE> (for true).Otherwise, the generated sequence is either<CODE>false</CODE> (for false), or<CODE>true</CODE> (for true). Thefunction then calls <CODE>width(0)</CODE> to reset thefield width to zero.The function returns <CODE>*this</CODE>.</P><P>The functions:</P><PRE>ostream&amp; <B>operator&lt;&lt;</B>(short val);ostream&amp; <B>operator&lt;&lt;</B>(unsigned short val);ostream&amp; <B>operator&lt;&lt;</B>(int val);ostream&amp; <B>operator&lt;&lt;</B>(unsigned int val);ostream&amp; <B>operator&lt;&lt;</B>(long val);ostream&amp; <B>operator&lt;&lt;</B>(unsigned long val);ostream&amp; <B>operator&lt;&lt;</B>(const void *val);</PRE><P>each convert <CODE>val</CODE> to an<B><A NAME="integer output field">integer output field</A></B>and inserts it. The equivalent<A HREF="lib_prin.html#print conversion specification">print conversionspecification</A> is determined as follows:</P><UL><LI>If <CODE><A HREF="ios.html#ios_base::flags">flags</A>() &amp;ios_base::<A HREF="ios.html#ios_base::basefield">basefield</A> ==ios_base::<A HREF="ios.html#ios_base::oct">oct</A></CODE>, the

⌨️ 快捷键说明

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