📄 ostream.html
字号:
basic_ostream& <B>seekp</B>(off_type off, ios_base::seek_dir way);</PRE><P>If <CODE><A HREF="ios.html#basic_ios::fail">fail</A>()</CODE> is false,the first member function calls<CODE>newpos = <A HREF="ios.html#basic_ios::rdbuf">rdbuf</A>()-><A HREF="streambu.html#basic_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#basic_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#basic_ios::setstate">setstate</A>(failbit)</CODE>.Both functions return <CODE>*this</CODE>.</P><H3><A NAME="basic_ostream::sentry"><CODE>basic_ostream::sentry</CODE></A></H3><PRE>class <B>sentry</B> {public: explicit <B>sentry</B>(basic_ostream<Elem, Tr>& 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#basic_ios::good">good</A>()</CODE> is true, and<CODE>ostr.<A HREF="ios.html#basic_ios::tie">tie</A>()</CODE> is nota null pointer, the constructor calls<CODE>ostr.tie-><A HREF="#basic_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<P><CODE><A HREF="exceptio.html#uncaught_exception">uncaught_exception</A>()</CODE>returns false and<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="#basic_ostream::flush">flush</A>()</CODE>.</P><H3><A NAME="basic_ostream::tellp"><CODE>basic_ostream::tellp</CODE></A></H3><PRE>pos_type <B>tellp</B>();</PRE><P>If <CODE><A HREF="ios.html#basic_ios::fail">fail</A>()</CODE> is false,the member function returns<CODE><A HREF="ios.html#basic_ios::rdbuf">rdbuf</A>()-><A HREF="streambu.html#basic_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="basic_ostream::write"><CODE>basic_ostream::write</CODE></A></H3><PRE>basic_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>template class<Elem, Tr> basic_ostream<Elem, Tr>& <B>endl</B>(basic_ostream<Elem, Tr>& ostr);</PRE><P>The manipulator calls<CODE>ostr.<A HREF="#basic_ostream::put">put</A>(ostr.<A HREF="ios.html#basic_ios::widen">widen</A>('\n'))</CODE>,then calls<CODE>ostr.<A HREF="#basic_ostream::flush">flush</A>()</CODE>.It returns <CODE>ostr</CODE>.</P><H2><A NAME="ends"><CODE>ends</CODE></A></H2><PRE>template class<Elem, Tr> basic_ostream<Elem, Tr>& <B>ends</B>(basic_ostream<Elem, Tr>& ostr);</PRE><P>The manipulator calls<CODE>ostr.<A HREF="#basic_ostream::put">put</A>(Elem('\0'))</CODE>.It returns <CODE>ostr</CODE>.</P><H2><A NAME="flush"><CODE>flush</CODE></A></H2><PRE>template class<Elem, Tr> basic_ostream<Elem, Tr>& <B>flush</B>(basic_ostream<Elem, Tr>& ostr);</PRE><P>The manipulator calls<CODE>ostr.<A HREF="#basic_ostream::flush">flush</A>()</CODE>.It returns <CODE>ostr</CODE>.</P><H2><A NAME="operator<<"><CODE>operator<<</CODE></A></H2><PRE>template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B>operator<<</B>(basic_ostream<Elem, Tr>& ostr, const Elem *str);template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B>operator<<</B>(basic_ostream<Elem, Tr>& ostr, Elem ch); template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B><A HREF="#operator<<">operator<<</A></B>(basic_ostream<Elem, Tr>& ostr, const char *str); template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B><A HREF="#operator<<">operator<<</A></B>(basic_ostream<Elem, Tr>& ostr, char ch); template<class Tr> basic_ostream<char, Tr>& <B><A HREF="#operator<<">operator<<</A></B>(basic_ostream<char, Tr>& ostr, const char *str); template<class Tr> basic_ostream<char, Tr>& <B><A HREF="#operator<<">operator<<</A></B>(basic_ostream<char, Tr>& ostr, char ch);template<class Tr> basic_ostream<char, Tr>& <B>operator<<</B>(basic_ostream<char, Tr>& ostr, const signed char *str);template<class Tr> basic_ostream<char, Tr>& <B>operator<<</B>(basic_ostream<char, Tr>& ostr, signed char ch);template<class Tr> basic_ostream<char, Tr>& <B>operator<<</B>(basic_ostream<char, Tr>& ostr, const unsigned char *str);template<class Tr> basic_ostream<char, Tr>& <B>operator<<</B>(basic_ostream<char, Tr>& ostr, unsigned char ch);</PRE><P>The template function:</P><PRE>template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B>operator<<</B>(basic_ostream<Elem, Tr>& ostr, const Elem *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 template function:</P><PRE>template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B>operator<<</B>(basic_ostream<Elem, Tr>& ostr, Elem 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 template function:</P><PRE>template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B>operator<<</B>(basic_ostream<Elem, Tr>& ostr, const char *str);</PRE><P>behaves the same as:</P><PRE>template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B>operator<<</B>(basic_ostream<Elem, Tr>& ostr, const Elem *str);</PRE><P>except that each element <CODE>ch</CODE> of the sequence beginningat <CODE>str</CODE> is converted to an object of type <CODE>Elem</CODE> by calling<CODE>ostr.<A HREF="#basic_ostream::put">put</A>(ostr.<A HREF="ios.html#basic_ios::widen">widen</A>(ch))</CODE>.</P><P>The template function:</P><PRE>template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B>operator<<</B>(basic_ostream<Elem, Tr>& ostr, char ch);</PRE><P>behaves the same as:</P><PRE>template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B>operator<<</B>(basic_ostream<Elem, Tr>& ostr, Elem ch);</PRE><P>except that <CODE>ch</CODE> is converted to an objectof type <CODE>Elem</CODE> by calling<CODE>ostr.<A HREF="#basic_ostream::put">put</A>(ostr.<A HREF="ios.html#basic_ios::widen">widen</A>(ch))</CODE>.</P><P>The template function:</P><PRE>template<class Tr> basic_ostream<char, Tr>& <B>operator<<</B>(basic_ostream<char, Tr>& ostr, const char *str);</PRE><P>behaves the same as:</P><PRE>template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B>operator<<</B>(basic_ostream<Elem, Tr>& ostr, const Elem *str);</PRE><P>(It does not have to widen the elements before inserting them.)</P><P>The template function:</P><PRE>template<class Tr> basic_ostream<char, Tr>& <B>operator<<</B>(basic_ostream<char, Tr>& ostr, char ch);</PRE><P>behaves the same as:</P><PRE>template<class Elem, class Tr> basic_ostream<Elem, Tr>& <B>operator<<</B>(basic_ostream<Elem, Tr>& ostr, Elem ch);</PRE><P>(It does not have to widen <CODE>ch</CODE> before inserting it.)</P><P>The template function:</P><PRE>template<class Tr> basic_ostream<char, Tr>& <B>operator<<</B>(basic_ostream<char, Tr>& ostr, const signed char *str);</PRE><P>returns <CODE>ostr << (const char *)str</CODE>.</P><P>The template function:</P><PRE>template<class Tr> basic_ostream<char, Tr>& <B>operator<<</B>(basic_ostream<char, Tr>& ostr, signed char ch);</PRE><P>returns <CODE>ostr << (char)ch</CODE>.</P><P>The template function:</P><PRE>template<class Tr> basic_ostream<char, Tr>& <B>operator<<</B>(basic_ostream<char, Tr>& ostr, const unsigned char *str);</PRE><P>returns <CODE>ostr << (const char *)str</CODE>.</P><P>The template function:</P><PRE>template<class Tr> basic_ostream<char, Tr>& <B>operator<<</B>(basic_ostream<char, Tr>& ostr, unsigned char ch);</PRE><P>returns <CODE>ostr << (char)ch</CODE>.</P><H2><A NAME="ostream"><CODE>ostream</CODE></A></H2><PRE>typedef basic_ostream<char, char_traits<char> > <B>ostream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_ostream"><CODE>basic_ostream</CODE></A>, specializedfor elements of type <I>char</I> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="wostream"><CODE>wostream</CODE></A></H2><PRE>typedef basic_ostream<wchar_t, char_traits<wchar_t> > <B>wostream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_ostream"><CODE>basic_ostream</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 + -