📄 iostream.html
字号:
<HTML><HEAD><TITLE><iostream></TITLE></HEAD><BODY><H1><A NAME="<iostream>"><CODE><iostream></CODE></A></H1><HR><P>Include the <A HREF="lib_cpp.html#iostreams">iostreams</A>standard header <B><CODE><iostream></CODE></B>to declare objects that control reading from and writing to the<A HREF="lib_over.html#standard streams">standard streams</A>.This is often the <I>only</I> header youneed include to perform input and output from a C++ program.</P><P>All the objects declared in this header share a peculiarproperty -- you can assume they are<B><A NAME="constructing iostreams">constructed</A></B> before anystatic objects you define, in a translation unit that includes<CODE><iostreams></CODE>. Equally, you can assume thatthese objects are <B>not destroyed</B> before the destructors for anysuch static objects you define. (The output streams are, however,flushed during program termination.)Hence, you can safely read fromor write to the standard streams prior to program startup andafter program termination.</P><P>This guarantee is <I>not</I> universal, however. A staticconstructor may call a function in another translation unit.The called function cannot assume that the objects declared inthis header have been constructed, given the uncertain orderin which translation units participate in static construction.To use these objects in such a context, you must first constructan object of class<B><CODE><A HREF="ios.html#ios_base::Init">ios_base::Init</A></CODE></B>,as in:</P><PRE>#include <iostream>void marker() { // called by some constructor ios_base::Init unused_name; cout << "called fun" << endl; }</PRE><PRE> // DECLARATIONSextern istream <B><A HREF="#cin">cin</A></B>;extern ostream <B><A HREF="#cout">cout</A></B>; // END OF DECLARATIONS</PRE><H2><CODE><A NAME="cin">cin</A></CODE></H2><PRE>extern istream cin;</PRE><P>The object controls extractions from the<A HREF="lib_over.html#standard input">standard input</A>as a <A HREF="lib_file.html#byte stream">byte stream</A>.Once the object is constructed, the call<CODE>cin.<A HREF="ios.html#ios::tie">tie</A>()</CODE> returns<CODE>&<A HREF="#cout">cout</A></CODE>.</P><H2><CODE><A NAME="cout">cout</A></CODE></H2><PRE>extern ostream cout;</PRE><P>The object controls insertions to the<A HREF="lib_over.html#standard output">standard output</A>as a <A HREF="lib_file.html#byte stream">byte stream</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 + -