📄 page_140.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>page_140</title> <link rel="stylesheet" href="reset.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <table summary="top nav" border="0" width="100%"> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_139.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_140</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_141.html">next page ></a></td> </tr> <tr> <td align="left" colspan="3" style="background: #ffffff; padding: 20px;"> <table border="0" width="100%" cellpadding="0"><tr><td align="center"> <table border="0" cellpadding="2" cellspacing="0" width="100%"><tr><td align="left"></td> <td align="right"></td> </tr></table></td></tr><tr><td align="left"><p></p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td align="right"><font face="Times New Roman, Times, Serif" size="2" color="#FF0000">Page 140</font></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3"><i>(table continued from previous page)</i></font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td height="12"></td></tr><tr><td><table cellspacing="0" width="557" cellpadding="7"><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2">2.</font></td><td valign="top"></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2"><img src="1c9eff0a24c07a6c21609e9186b427f5.gif" border="0" alt="a.gif" width="15" height="16" /> B\n<br /></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">CD\n</font></td></tr><tr><td valign="top"><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="29" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td> <td colspan="3" height="1"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">cin.get(ch1);</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">ch1</font><font face="Times New Roman, Times, Serif" size="2"> =A</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">A<img src="72a5b83b3b83c610e6911c571b400d71.gif" border="0" alt="sbox.gif" width="14" height="16" /> B\n<br /></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">CD\n</font></td></tr><tr><td valign="top"><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="29" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td> <td colspan="3" height="1"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">cin.get(ch2);</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">ch2</font><font face="Times New Roman, Times, Serif" size="2"> =</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">A<img src="4c1ea8029e65fb9bc860bbecafcbc679.gif" border="0" alt="b.gif" width="14" height="16" /> \n<br /></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">CD\n</font></td></tr><tr><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">cin.get(ch3);</font></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">ch3</font><font face="Times New Roman, Times, Serif" size="2"> =B</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">A B<img src="c87ad29ccb4c3043fda0d0a93a820a4a.gif" border="0" alt="slashn.gif" width="21" height="17" /><br /></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">CD\n</font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2">3.</font></td><td valign="top"></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2"><img src="1c9eff0a24c07a6c21609e9186b427f5.gif" border="0" alt="a.gif" width="15" height="16" /> B\n<br /></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">CD\n</font></td></tr><tr><td valign="top"><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="29" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td> <td colspan="3" height="1"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">cin聽>>聽ch1;</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">ch1</font><font face="Times New Roman, Times, Serif" size="2"> =A</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">A<img src="72a5b83b3b83c610e6911c571b400d71.gif" border="0" alt="sbox.gif" width="14" height="16" /> B\n<br /></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">CD\n</font></td></tr><tr><td valign="top"><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="29" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td> <td colspan="3" height="1"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">cin聽>>聽ch2;</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">ch2</font><font face="Times New Roman, Times, Serif" size="2"> =B</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">A B<img src="c87ad29ccb4c3043fda0d0a93a820a4a.gif" border="0" alt="slashn.gif" width="21" height="17" /><br /></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">CD\n</font></td></tr><tr><td valign="top"><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="29" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td> <td colspan="3" height="1"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">cin.get(ch3);</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">ch3</font><font face="Times New Roman, Times, Serif" size="2"> = \n</font></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">A聽B\n<br /></font><font face="Times New Roman, Times, Serif" size="2"><img src="5613977a71d9e2a180edebe594a99e44.gif" border="0" alt="c.gif" width="15" height="17" /> D\n</font></td></tr></table></td></tr></table><br /><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">You may be puzzled about the peculiar syntax in a function call like</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">cin.get(ch1);</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">This statement uses a C++ notation called <i>dot notation.</i> There is a dot (period) between the variable name </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">cin</font><font face="Times New Roman, Times, Serif" size="3"> and the function name </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">get</font><font face="Times New Roman, Times, Serif" size="3">. Certain predefined data types, like </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">istream</font><font face="Times New Roman, Times, Serif" size="3"> and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ostream</font><font face="Times New Roman, Times, Serif" size="3">, have functions that are tightly associated with them, and dot notation is required in the function calls. If you forget to use dot notation by using</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">get(ch1);</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">you get a compile-time error message, something like UNDECLARED IDENTIFIER. The compiler thinks you are trying to call an ordinary function named </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">get</font><font face="Times New Roman, Times, Serif" size="3">, not the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">get</font><font face="Times New Roman, Times, Serif" size="3"> function associated with the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">istream</font><font face="Times New Roman, Times, Serif" size="3"> type.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Another example you saw in the last chapter is the function call that forces decimal points to appear in the output of all floating point numbers:</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">cout.setf(ios::showpoint);</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td></tr></table><p><font size="0"></font></p>聽 </td> </tr> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_139.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_140</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_141.html">next page ></a></td> </tr> </table> </body> </html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -