📄 lib_cpp.html
字号:
You can subsequently ignore namespaceconsiderations in the remainder of the translation unit.You also avoid most dialect differences across differenttranslation environments.</P><P>Unless specifically indicated otherwise, you may not define names inthe <CODE>std</CODE> namespace, or in a namespace nested within the<CODE>std</CODE> namespace.</P><H2><A NAME="C++ Library Conventions">C++ Library Conventions</A></H2><P>The C++ library obeys much the same<A HREF="lib_over.html#C Library Conventions">conventions</A>as the Standard C library, plus a few more outlined here.<P>An implementation has certain latitude in how it declares typesand functions in the C++ library:</P><UL><LI>Names of functions in the Standard C library may have either<B><A NAME="extern "C++""><CODE>extern "C++"</CODE></A></B> or<B><A NAME="extern "C""><CODE>extern "C"</CODE></A></B> linkage.Include the appropriate<A HREF="lib_over.html#standard headers">Standard C header</A>rather than declare a library entity inline.</LI><LI>A member function name in a library class may have additionalfunction signatures over those listed in this document. You canbe sure that a function call described here behaves as expected,but you cannot reliably take the address of a library member function.(The type may not be what you expect.)</LI><LI>A library class may have undocumented (non-virtual) base classes.A class documented as derived from another class may, in fact,be derived from that class through other undocumented classes.</LI><LI>A type defined as a synonym for some integer type may be thesame as one of several different integer types.</LI><LI>A <B><A NAME="bitmask type">bitmask type</A></B> canbe implemented as either an integer type or an enumeration.In either case, you can perform bitwise operations (such as ANDand OR) on values of the same bitmask type. The <I>elements</I><CODE>A</CODE> and <CODE>B</CODE> of a bitmask type are nonzerovalues such that <CODE>A & B</CODE> is zero.</LI><LI>A library function that has no exception specification canthrow an arbitrary exception, unless its definition clearlyrestricts such a possibility.</LI></UL><P>On the other hand, there are some restrictions you can count on:</P><UL><LI>The Standard C library uses no<A NAME="masking macro">masking macros</A>. Only specific functionsignatures are reserved, not the names of the functions themselves.</LI><LI>A library function name outside a class will <I>not</I> haveadditional, undocumented, function signatures. You can reliablytake its address.</LI><LI>Base classes and member functions described as virtual areassuredly virtual, while those described as non-virtual areassuredly non-virtual.</LI><LI>Two types defined by the C++ libraryare always different unless this document explicitly suggestsotherwise.</LI><LI>Functions supplied by the library, including the default versions of<A HREF="new.html#replaceable functions">replaceable functions</A>,can throw <I>at most</I> those exceptions listed in any exceptionspecification.No destructors supplied by the library throw exceptions.Functions in the<A HREF="index.html#Standard C Library">Standard C library</A>may propagate an exception, as when<CODE><A HREF="stdlib.html#qsort">qsort</A></CODE> calls a comparisonfunction that throws an exception, but they do not otherwise throwexceptions.</LI></UL><H2><A NAME="iostreams">Iostreams Conventions</A></H2><P>The <B>iostreams</B> headers support conversionsbetween text and encoded forms, and input and output to external<A HREF="lib_file.html#files">files</A>:<CODE><A HREF="fstream.html"><fstream></A></CODE>,<CODE><A HREF="iomanip.html"><iomanip></A></CODE>,<CODE><A HREF="ios.html"><ios></A></CODE>,<CODE><A HREF="iosfwd.html"><iosfwd></A></CODE>,<CODE><A HREF="iostream.html"><iostream></A></CODE>,<CODE><A HREF="istream.html"><istream></A></CODE>,<CODE><A HREF="ostream.html"><ostream></A></CODE>,<CODE><A HREF="sstream.html"><sstream></A></CODE>,<CODE><A HREF="streambu.html"><streambuf></A></CODE>, and<CODE><A HREF="strstrea.html"><strstream></A></CODE>.</P><P>The simplest use of iostreams requires only that you includethe header <CODE><iostream></CODE>. You can then extract values from<A HREF="iostream.html#cin"><CODE>cin</CODE></A>, to read the<A HREF="lib_over.html#standard input">standard input</A>.The rules for doing so are outlined in the description of the class<CODE><A HREF="istream.html#basic_istream">basic_istream</A></CODE>.You can also insert values to<A HREF="iostream.html#cout"><CODE>cout</CODE></A>, to write the<A HREF="lib_over.html#standard output">standard output</A>.The rules for doing so are outlined in the description of the class<CODE><A HREF="ostream.html#basic_ostream">basic_ostream</A></CODE>.Format control common to both extractors and insertors is managedby the class <CODE><A HREF="ios.html#basic_ios">basic_ios</A></CODE>.Manipulating this format information in the guise of extracting andinserting objects is the province of several<A HREF="iomanip.html">manipulators</A>.</P><P>You can perform the same iostreams operations on files that youopen by name, using the classes declared in<CODE><fstream></CODE>.To convert between iostreams and objects of class<CODE><A HREF="string2.html#basic_string">basic_string</A></CODE>,use the classes declared in <CODE><sstream></CODE>.And to do the same with <A HREF="lib_over.html#C string">C strings</A>,use the classes declared in <CODE><strstream></CODE>.</P><P>The remaining headers provide support services, typically of directinterest to only the most advanced users of the iostreams classes.</P><H2><A NAME="C++ Program Startup and Termination">C++ Program Startup and Termination</A></H2><P>A C++ program performs the same operations as does a C program<A HREF="lib_over.html#program startup">program startup</A> and at<A HREF="lib_over.html#program termination">program termination</A>,plus a few more outlined here.</P><P>Before the target environment calls the function<A HREF="lib_over.html#main"><CODE>main</CODE></A>, and after it storesany constant initial values you specify in all objects that havestatic duration, the program executes any remaining constructorsfor such static objects. The order of execution is not specifiedbetween translation units, but you can nevertheless assume that some<A HREF="#iostreams">iostreams</A> objects are properly initializedfor use by these static constructors. These controltext streams:</P><UL><LI><B><A HREF="iostream.html#cin"><CODE>cin</CODE></A></B> --for <A HREF="lib_over.html#standard input">standard input</A></LI><LI><B><A HREF="iostream.html#cout"><CODE>cout</CODE></A></B> --for <A HREF="lib_over.html#standard output">standard output</A></LI><LI><B><A HREF="iostream.html#cerr"><CODE>cerr</CODE></A></B> --for unbuffered<A HREF="lib_over.html#standard error">standard error</A> output</LI><LI><B><A HREF="iostream.html#clog"><CODE>clog</CODE></A></B> --for buffered<A HREF="lib_over.html#standard error">standard error</A> output</LI></UL><P>You can also use these objects within the destructors called forstatic objects, during<A HREF="lib_over.html#program termination">program termination</A>.<P>As with C, returningfrom <A HREF="lib_over.html#main"><CODE>main</CODE></A> or calling<A HREF="stdlib.html#exit"><CODE>exit</CODE></A>calls all functions registered with<A HREF="stdlib.html#atexit"><CODE>atexit</CODE></A>in reverse order of registry.An exception thrown from such a registered function calls<CODE><A HREF="exceptio.html#terminate">terminate</A>()</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 + -