📄 ostream.html
字号:
conversion specification is <CODE>lo</CODE> and the converted value is<CODE>(long)val</CODE>.</LI><LI>If <CODE>flags() & ios_base::basefield ==ios_base::<A HREF="ios.html#ios_base::hex">hex</A></CODE>, theconversion specification is <CODE>lx</CODE> and the converted value is<CODE>(unsigned long)val</CODE>.</LI><LI>Otherwise, the conversion specification is <CODE>ld</CODE>and the converted value is <CODE>(long)val</CODE>.</LI></UL><P>If <CODE><A HREF="ios.html#ios_base::width">width</A>()</CODE>is nonzero, a field width of this value is prepended. Thefunction then calls <CODE>width(0)</CODE> to reset thefield width to zero.</P><P>Finally:</P><UL><LI>If <CODE>flags() &ios_base::<A HREF="ios.html#ios_base::showpos">showpos</A></CODE>is nonzero, the flag <CODE>+</CODE> is prepended to the conversionspecification.</LI><LI>If <CODE>flags() &ios_base::<A HREF="ios.html#ios_base::showbase">showbase</A></CODE>is nonzero, the flag <CODE>#</CODE> is prepended to the conversionspecification.</LI></UL><P>The function returns <CODE>*this</CODE>.</P><P>The functions:</P><PRE>ostream& <B>operator<<</B>(float val);ostream& <B>operator<<</B>(double val);ostream& <B>operator<<</B>(long double val);</PRE><P>each convert <CODE>val</CODE> to a<B><A NAME="floating-point output field">floating-point output field</A></B>and insert it.A period (<CODE>.</CODE>) separates the integer digits from thefraction digits.The equivalent print conversion specification is determined as follows:</P><UL><LI>If <CODE><A HREF="ios.html#ios_base::flags">flags</A>() &ios_base::<A HREF="ios.html#ios_base::floatfield">floatfield</A> ==ios_base::<A HREF="ios.html#ios_base::fixed">fixed</A></CODE>, theconversion specification is <CODE>f</CODE>.</LI><LI>If <CODE>flags() & ios_base::floatfield ==ios_base::<A HREF="ios.html#ios_base::scientific">scientific</A></CODE>, theconversion specification is <CODE>e</CODE>.If <CODE>flags() &ios_base::<A HREF="ios.html#ios_base::uppercase">uppercase</A></CODE>is nonzero, <CODE>e</CODE> is replaced with <CODE>E</CODE>.</LI><LI>Otherwise, the conversion specification is <CODE>g</CODE>.If <CODE>flags() & ios_base::uppercase</CODE>is nonzero, <CODE>g</CODE> is replaced with <CODE>G</CODE>.</LI></UL><P>If <CODE>val</CODE> has type <I>double,</I> the function prepends <CODE>l</CODE>to the conversion specification. If <CODE>val</CODE> has type <I>long double,</I>it prepends <CODE>L</CODE> to the conversion specification.</P><P>If <CODE>flags() & ios_base::fixed</CODE> is nonzero, or if<CODE><A HREF="ios.html#ios_base::precision">precision</A>()</CODE>is greater than zero, a precision with the value<CODE>precision()</CODE> is prepended to the conversion specification.Any <A HREF="#padding">padding</A> behaves the sameas for an integer output field.<P>If <CODE><A HREF="ios.html#ios_base::width">width</A>()</CODE>is nonzero, a field width of this value is prepended. Thefunction then calls <CODE>width(0)</CODE> to reset thefield width to zero. Finally:</P><UL><LI>If <CODE>flags() &ios_base::<A HREF="ios.html#ios_base::showpos">showpos</A></CODE>is nonzero, the flag <CODE>+</CODE> is prepended to the conversionspecification.</LI><LI>If <CODE>flags() &ios_base::<A HREF="ios.html#ios_base::showpoint">showpoint</A></CODE>is nonzero, the flag <CODE>#</CODE> is prepended to the conversionspecification.</LI></UL><H3><A NAME="ostream::put"><CODE>ostream::put</CODE></A></H3><PRE>ostream& <B><A HREF="#ostream::put">put</A></B>(char_type ch);</PRE><P>The <A HREF="#unformatted output functions">unformatted output function</A>inserts the element <CODE>ch</CODE>. It returns <CODE>*this</CODE>.</P><H3><A NAME="ostream::seekp"><CODE>ostream::seekp</CODE></A></H3><PRE>ostream& <B>seekp</B>(pos_type pos);ostream& <B>seekp</B>(off_type off, ios_base::seek_dir way);</PRE><P>If <CODE><A HREF="ios.html#ios::fail">fail</A>()</CODE> is false,the first member function calls<CODE>newpos = <A HREF="ios.html#ios::rdbuf">rdbuf</A>()-><A HREF="streambu.html#streambuf::pubseekpos">pubseekpos</A>(pos,<A HREF="ios.html#ios_base::out">out</A>)</CODE>,for some <CODE>pos_type</CODE> temporary object <CODE>newpos</CODE>.If <CODE>fail()</CODE> is false, the second function calls<CODE>newpos = rdbuf()-><A HREF="streambu.html#streambuf::pubseekoff">pubseekoff</A>(off, way,<A HREF="ios.html#ios_base::out">out</A>)</CODE>.In either case, if <CODE>(off_type)newpos == (off_type)(-1)</CODE>(the positioning operation fails) the function calls<CODE>istr.<A HREF="ios.html#ios::setstate">setstate</A>(failbit)</CODE>.Both functions return <CODE>*this</CODE>.</P><H3><A NAME="ostream::sentry"><CODE>ostream::sentry</CODE></A></H3><PRE>class <B>sentry</B> {public: explicit <B>sentry</B>(ostream& ostr); <B>operator bool</B>() const; <B>~sentry</B>();private: <B>sentry</B>(const sentry&); // not defined sentry& <B>operator=</B>(const sentry&); // not defined bool <B>status</B>; };</PRE><P>The nested class describes an object whose declaration structures the<A HREF="#formatted output functions">formatted output functions</A>and the<A HREF="#unformatted output functions">unformatted output functions</A>.If <CODE>ostr.<A HREF="ios.html#ios::good">good</A>()</CODE> is true, and<CODE>ostr.<A HREF="ios.html#ios::tie">tie</A>()</CODE> is nota null pointer, the constructor calls<CODE>ostr.tie-><A HREF="#ostream::flush">flush</A>()</CODE>.The constructor then stores the value returned by <CODE>ostr.good()</CODE>in <B>status</B>.A later call to <CODE>operator bool()</CODE> delivers this stored value.</P><P>If<CODE><A HREF="ios.html#ios_base::flags">flags</A>() &<A HREF="ios.html#ios_base::unitbuf">unitbuf</A></CODE> is nonzero,the destructor calls<CODE><A HREF="#ostream::flush">flush</A>()</CODE>.</P><H3><A NAME="ostream::tellp"><CODE>ostream::tellp</CODE></A></H3><PRE>pos_type <B>tellp</B>();</PRE><P>If <CODE><A HREF="ios.html#ios::fail">fail</A>()</CODE> is false,the member function returns<CODE><A HREF="ios.html#ios::rdbuf">rdbuf</A>()-><A HREF="streambu.html#streambuf::pubseekoff">pubseekoff</A>(0,<A HREF="ios.html#ios_base::cur">cur</A>,<A HREF="ios.html#ios_base::in">in</A>)</CODE>.Otherwise, it returns <CODE>pos_type(-1)</CODE>.</P><H3><A NAME="ostream::write"><CODE>ostream::write</CODE></A></H3><PRE>ostream& <B>write</B>(const char_type *str, streamsize count);</PRE><P>The <A HREF="#unformatted output functions">unformatted output function</A>inserts the sequence of <CODE>count</CODE> elementsbeginning at <CODE>str</CODE>.</P><H2><A NAME="endl"><CODE>endl</CODE></A></H2><PRE>ostream <B>endl</B>(ostream& ostr);</PRE><P>The manipulator calls<CODE>ostr.<A HREF="#ostream::put">put</A>(ostr.<A HREF="ios.html#ios::widen">widen</A>('\n'))</CODE>,then calls<CODE>ostr.<A HREF="#ostream::flush">flush</A>()</CODE>.It returns <CODE>ostr</CODE>.</P><H2><A NAME="ends"><CODE>ends</CODE></A></H2><PRE>ostream& <B>ends</B>(ostream& ostr);</PRE><P>The manipulator calls<CODE>ostr.<A HREF="#ostream::put">put</A>(Elem('\0'))</CODE>.It returns <CODE>ostr</CODE>.</P><H2><A NAME="flush"><CODE>flush</CODE></A></H2><PRE>ostream& <B>flush</B>(ostream& ostr);</PRE><P>The manipulator calls<CODE>ostr.<A HREF="#ostream::flush">flush</A>()</CODE>.It returns <CODE>ostr</CODE>.</P><H2><A NAME="operator<<"><CODE>operator<<</CODE></A></H2><PRE>ostream& <B>operator<<</B>(ostream& ostr, const char *str);ostream& <B>operator<<</B>(ostream& ostr, char ch);ostream& <B>operator<<</B>(ostream& ostr, const signed char *str);ostream& <B>operator<<</B>(ostream& ostr, signed char ch);ostream& <B>operator<<</B>(ostream& ostr, const unsigned char *str);ostream& <B>operator<<</B>(ostream& ostr, unsigned char ch);</PRE><P>All of these functions are<A HREF="#formatted output functions">formatted output functions</A>.The function:</P><PRE>ostream& <B>operator<<</B>(ostream& ostr, const char *str);</PRE><P>determines the length <CODE>N =traits_type::<A HREF="string2.html#char_traits::length">length</A>(str)</CODE>of the sequence beginning at <CODE>str</CODE>, and inserts the sequence. If<CODE>N < ostr.<A HREF="ios.html#ios_base::width">width</A>()</CODE>,then the function also inserts a repetition of <CODE>ostr.width() - N</CODE><A HREF="ios.html#fill character">fill characters</A>.The repetition precedes the sequence if<CODE>(ostr.<A HREF="ios.html#ios_base::flags">flags</A>() &<A HREF="ios.html#ios_base::adjustfield">adjustfield</A> !=<A HREF="ios.html#ios_base::left">left</A></CODE>.Otherwise, the repetition follows the sequence.The function returns <CODE>ostr</CODE>.</P><P>The function:</P><PRE>ostream& <B>operator<<</B>(ostream& ostr, char ch);</PRE><P>inserts the element <CODE>ch</CODE>. If<CODE>1 < ostr.<A HREF="ios.html#ios_base::width">width</A>()</CODE>,then the function also inserts a repetition of <CODE>ostr.width() - 1</CODE><A HREF="ios.html#fill character">fill characters</A>.The repetition precedes the sequence if<CODE>(ostr.<A HREF="ios.html#ios_base::flags">flags</A>() &<A HREF="ios.html#ios_base::adjustfield">adjustfield</A> !=<A HREF="ios.html#ios_base::left">left</A></CODE>.Otherwise, the repetition follows the sequence.It returns <CODE>ostr</CODE>.</P><P>The function:</P><PRE>ostream& <B>operator<<</B>(ostream& ostr, const signed char *str);</PRE><P>returns <CODE>ostr << (const char *)str</CODE>.</P><P>The function:</P><PRE>ostream& <B>operator<<</B>(ostream& ostr, signed char ch);</PRE><P>returns <CODE>ostr << (char)ch</CODE>.</P><P>The function:</P><PRE>ostream& <B>operator<<</B>(ostream& ostr, const unsigned char *str);</PRE><P>returns <CODE>ostr << (const char *)str</CODE>.</P><P>The function:</P><PRE>ostream& <B>operator<<</B>(ostream& ostr, unsigned char ch);</PRE><P>returns <CODE>ostr << (char)ch</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 + -