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

📄 ch28.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 4 页
字号:


examples of class libraries are class libraries that handle database access, class



libraries that handle graphical user interface programming, and class libraries that



implement data structures.</P>



<P>Examples of graphical user interface class libraries include the Microsoft Foundation



Classes and Borland's Object Windows Library, both of which are class libraries that



are used for developing Windows applications.</P>



<P>This section introduces several of the features that are offered by the GNU C++



class library.



<CENTER>



<H4><A NAME="Heading16<FONT COLOR="#000077">Streams</FONT></H4>



</CENTER>



<P>The GNU iostream library, called <TT>libio</TT>, implements GNU C++'s standard



input and output facilities. This library is similar to the I/O libraries that are



supplied by other C++ compilers. The main parts of the iostream library are the input,



output, and error streams. These correspond to the standard input, output, and error



streams that are found in C and are called <TT>cin</TT>, <TT>cout</TT>, and <TT>cerr</TT>,



respectively. The streams can be written to and read from using the <TT>&lt;&lt;</TT>



operator for output and the <TT>&gt;&gt;</TT> operator for input.</P>



<P>The following program uses the iostream library to perform its input and output:</P>



<PRE><FONT COLOR="#0066FF">#include &lt;iostream.h&gt;



int maim ()



{      



        char name[10];



        cout &lt;&lt; &quot;Please enter your name.\n&quot;;



        cin &gt;&gt; name;



        cout &lt;&lt; &quot;Hello &quot; &lt;&lt; name &lt;&lt; &quot; how is it going?\n&quot;;



}



</FONT></PRE>



<CENTER>



<H4><A NAME="Heading17<FONT COLOR="#000077">Strings</FONT></H4>



</CENTER>



<P>The GNU string class extends GNU C++'s string manipulation capabilities. The string



class essentially replaces the character array definitions that existed in C and



all the string functions that go along with the character arrays.</P>



<P>The string class adds UNIX shell type string operators to the C++ language, as



well as a large number of additional operators. Table 28.4 lists many of the operators



that are available with the string class. <BR>







<CENTER>



<P><FONT SIZE="4"><B>Table 28.4.</B> String class operators. </FONT>



<TABLE BORDER="0">



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="127" ALIGN="LEFT"><I>Operator</I></TD>



		<TD ALIGN="LEFT"><I>Meaning</I></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="127" ALIGN="LEFT"><TT>str1 == str2</TT></TD>



		<TD ALIGN="LEFT">Returns <TT>TRUE</TT> if <TT>str1</TT> is equal to <TT>str2</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="127" ALIGN="LEFT"><TT>str1 != str2</TT></TD>



		<TD ALIGN="LEFT">Returns <TT>TRUE</TT> if <TT>str1</TT> is not equal to <TT>str2</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="127" ALIGN="LEFT"><TT>str1 &lt; str2</TT></TD>



		<TD ALIGN="LEFT">Returns <TT>TRUE</TT> if <TT>str1</TT> is less than <TT>str2</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="127" ALIGN="LEFT"><TT>str1 &lt;= str2</TT></TD>



		<TD ALIGN="LEFT">Returns <TT>TRUE</TT> if <TT>str1</TT> is less than or equal to <TT>str2</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="127" ALIGN="LEFT"><TT>str1 &gt; str2</TT></TD>



		<TD ALIGN="LEFT">Returns <TT>TRUE</TT> if <TT>str1</TT> is greater than <TT>str2</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="127" ALIGN="LEFT"><TT>str1 &gt;= str2</TT></TD>



		<TD ALIGN="LEFT">Returns <TT>TRUE</TT> if <TT>str1</TT> is greater than or equal to <TT>str2</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="127" ALIGN="LEFT"><TT>compare(str1,str2)</TT></TD>



		<TD ALIGN="LEFT">Compares <TT>str1</TT> to <TT>str2</TT> without considering the case of the <BR>



			characters</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="127" ALIGN="LEFT"><TT>str3 = str1 + str2</TT></TD>



		<TD ALIGN="LEFT">Stores the result of <TT>str1</TT> concatenated with <TT>str2</TT> into <TT>str3</TT></TD>



	</TR>



</TABLE>







</CENTER>



<P><BR>



A number of other operators are available in the string class for performing different



types of string comparisons, concatenations, and substring extraction and manipulation.



<CENTER>



<H4><A NAME="Heading18<FONT COLOR="#000077">Random Numbers</FONT></H4>



</CENTER>



<P>Classes are provided in the GCC C++ class library that allow you to generate several



different kinds of random numbers. The classes used to generate these numbers are



the <TT>Random</TT> class and the <TT>RNG</TT> class.



<CENTER>



<H4><A NAME="Heading19<FONT COLOR="#000077">Data Collection</FONT></H4>



</CENTER>



<P>The class library provides two different classes that perform data collection



and analysis functions. The two classes are <TT>SampleStatistic</TT> and <TT>SampleHistogram</TT>.



The <TT>SampleStatistic</TT> class provides a way of collecting samples and also



provides numerous statistical functions that can perform calculations on the collected



data. Some of the calculations that can be performed are mean, variance, standard



deviation, minimum, and maximum.</P>



<P>The <TT>SampleHistogram</TT> class is derived from the <TT>SampleStatistic</TT>



class and supports the collection and display of samples in bucketed intervals.



<CENTER>



<H4><A NAME="Heading20<FONT COLOR="#000077">Linked Lists</FONT></H4>



</CENTER>



<P>The GNU C++ library supports two kinds of linked lists: single linked lists, implemented



by the <TT>SLList</TT> class, and doubly linked lists, implemented by the <TT>DLList</TT>



class. Both of these types of lists support all the standard linked list operations.



A summary of the operations that these classes support is shown in Table 28.5. <BR>



<BR>



<FONT SIZE="4"><B>Table 28.5.</B> List operators. </FONT>



<TABLE BORDER="0">



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><I>Operator</I></TD>



		<TD ALIGN="LEFT"><I>Description</I></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.empty()</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Returns <TT>TRUE</TT> if <TT>list</TT> is empty</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.length()</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Returns the number of elements in <TT>list</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.prepend(a)</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Places <TT>a</TT> at the front of <TT>list</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.append(a)</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Places <TT>a</TT> at the end of <TT>list</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.join(list2)</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Appends <TT>list2</TT> to <TT>list</TT>, destroying <TT>list2</TT> in the process</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>a = list.front()</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Returns a pointer to the element that is stored at the head of the list</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>a = list.rear()</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Returns a pointer to the element that is stored at the end of the list</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>a = list.remove_front()</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Deletes and returns the element that is stored at the front of the list</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.del_front()</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Deletes the first element without returning it</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.clear()</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Deletes all items from <TT>list</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.ins_after(i, a)</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Inserts <TT>a</TT> after position <TT>i</TT> in the list</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.del_after(i)</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Deletes the element following position <TT>i</TT> in the list</TD>



	</TR>



</TABLE>



<BR>



Doubly linked lists also support the operations listed in Table 28.6. </P>



<CENTER>



<P><FONT SIZE="4"><B>Table 28.6.</B> Doubly linked list operators.</FONT> 



<TABLE BORDER="0">



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><I>Operator</I></TD>



		<TD ALIGN="LEFT"><I>Description</I></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>a = list.remove_rear()</TT></TD>



		<TD ALIGN="LEFT">Deletes and returns the element stored at the end of the list</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.del_real()</TT></TD>



		<TD ALIGN="LEFT">Deletes the last element, without returning it</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.ins_before(i, a)</TT></TD>



		<TD ALIGN="LEFT">Inserts <TT>a</TT> before position <TT>i</TT> in the list</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>list.del(i, dir)</TT></TD>



		<TD ALIGN="LEFT">Deletes the element at the current position and then moves forward one position if



			<TT>dir</TT> is positive and backward one position if <TT>dir</TT> is 0 or negative</TD>



	</TR>



</TABLE>







</CENTER>



<CENTER>



<H4><A NAME="Heading21<FONT COLOR="#000077">Plex Classes</FONT></H4>



</CENTER>



<P>Plex classes are classes that behave like arrays but are much more powerful. Plex



classes have the following properties:







<UL>



	<LI>They have arbitrary upper and lower index bounds.



	<P>



	<LI>They can dynamically expand in both the lower and upper bound directions.



	<P>



	<LI>Elements may be accessed by indices. Unlike typical arrays, bounds checking is



	performed at runtime.



	<P>



	<LI>Only elements that have been specifically initialized or added can be accessed.



</UL>







<P>Four different types of Plexes are defined: the <TT>FPlex</TT>, the <TT>XPlex</TT>,



the <TT>RPlex</TT>, and the <TT>MPlex</TT>. The <TT>FPlex</TT> is a Plex that can



grow or shrink only within declared bounds. An <TT>XPlex</TT> can dynamically grow



in any direction without any restrictions. An <TT>RPlex</TT> is almost identical



to an <TT>XPlex</TT>, but it has better indexing capabilities. Finally, the <TT>MPlex</TT>



is the same as an <TT>RPlex</TT> except that it allows elements to be logically deleted



and restored.</P>



<P>Table 28.7 lists some of the operations that are valid on all four of the Plexes.



</P>



<CENTER>



<P><FONT SIZE="4"><B>Table 28.7.</B> Operations defined for Plexes. </FONT>



<TABLE BORDER="0">



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><I>Operation</I></TD>



		<TD ALIGN="LEFT"><I>Description</I></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>Plex b(a)</TT></TD>



		<TD ALIGN="LEFT">Assigns a copy of <TT>Plex a</TT> to <TT>Plex b</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>b = a</TT></TD>



		<TD ALIGN="LEFT">Copies <TT>Plex a</TT> into <TT>b</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>a.length()</TT></TD>



		<TD ALIGN="LEFT">Returns the number of elements in <TT>a</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>a.empty()</TT></TD>



		<TD ALIGN="LEFT">Returns <TT>TRUE</TT> if <TT>a</TT> has no elements</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>a.full()</TT></TD>



		<TD ALIGN="LEFT">Returns <TT>TRUE</TT> if <TT>a</TT> is full</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>a.clear()</TT></TD>



		<TD ALIGN="LEFT">Removes all the elements from <TT>a</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>a.append</TT></TD>



		<TD ALIGN="LEFT">Appends <TT>Plex b</TT> to the high part of <TT>a</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>a.prepend</TT></TD>



		<TD ALIGN="LEFT">Prepends <TT>Plex b</TT> to the low part of <TT>a</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>a.fill(z)</TT></TD>



		<TD ALIGN="LEFT">Sets all elements of <TT>a</TT> equal to <TT>z</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>a.valid(i)</TT></TD>



		<TD ALIGN="LEFT">Returns <TT>TRUE</TT> if <TT>i</TT> is a valid index into <TT>a</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>a.low_element()</TT></TD>



		<TD ALIGN="LEFT">Returns a pointer to the element in the lowest position in <TT>a</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>a.high_element()</TT></TD>



		<TD ALIGN="LEFT">Returns a pointer to the element in the highest position in <TT>a</TT></TD>



	</TR>



</TABLE>



⌨️ 快捷键说明

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