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

📄 page_139.html

📁 Programming and Problem Solving with C++
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">	<html>		<head>			<title>page_139</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_138.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_139</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_140.html">next page&nbsp;&gt;</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 139</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">the syntax for calling a void function, not a value-returning function. The function call is a complete statement; it is not part of a larger expression.</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">The effect of the above function call is to input the next character waiting in the streameven if it is a whitespace character like a blankand store it into the variable </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">someChar</font><font face="Times New Roman, Times, Serif" size="3">. The parameter to 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 <i>must</i> be a variable, not a constant or arbitrary expression; we must tell the function where we want it to store the input character.</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">Using 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, we now can input all three characters of the input line</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">R聽1</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">We can use three consecutive calls to 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</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);<br />cin.get(ch2);<br />cin.get(ch3);</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">or we can do it this way:</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聽&gt;&gt;聽ch1;<br />cin.get(ch2);<br />cin聽&gt;&gt;聽ch3;</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">The first version is probably a bit clearer for someone to read and understand.</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">Here are some more examples of character input using both the &gt;&gt; operator and 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. All of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ch1</font><font face="Times New Roman, Times, Serif" size="3">, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ch2</font><font face="Times New Roman, Times, Serif" size="3">, and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ch3</font><font face="Times New Roman, Times, Serif" size="3"> are </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">char</font><font face="Times New Roman, Times, Serif" size="3"> variables. As before, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">\n</font><font face="Times New Roman, Times, Serif" size="3"> denotes the newline character.</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"><i>Statements</i></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2"><i>Contents After Input</i></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2"><i>Marker Position in the Input Stream</i></font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2">1.</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聽&gt;&gt;聽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聽&gt;&gt;聽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聽&gt;&gt;聽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"> = C</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">A B\n<br />C<img src="fccb08e122f0c662834c84789ebb1d78.gif" border="0" alt="d.gif" width="14" height="15" /> \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"><i>(table continued on next page)</i></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_138.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_139</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_140.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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