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

📄 page_136.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_136</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_135.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_136</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_137.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 136</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">Examples (1) and (2) are straightforward examples of integer input. Example (3) shows that you do not use quotes around character data values when they are input (quotes around character constants are needed in a program, though, to distinguish them from identifiers). Example (4) demonstrates how the process of skipping whitespace characters includes going on to the next line of input if necessary. Example (5) shows that the first character encountered that is inappropriate for a numeric data type ends the number. Input for the variable </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">i</font><font face="Times New Roman, Times, Serif" size="3"> stops at the input character A, after which the A is stored into </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ch</font><font face="Times New Roman, Times, Serif" size="3">, and then input for </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">x</font><font face="Times New Roman, Times, Serif" size="3"> stops at the end of the input line. Example (6) shows that if you are at the keyboard and haven't entered enough values to satisfy the input statement, the computer waits (and waits and waits  ) for more data. Example (7) shows that if more values are entered than there are variables in the input statement, the extra values remain waiting in the input stream until they can be read by the next input statement. If there are extra values left when the program ends, the computer disregards them.</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"><i>The Reading Marker and the Newline Character</i></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">To help explain stream input in more detail, we introduce the concept of the <i>reading marker.</i> The reading marker works like a bookmark, but, instead of marking a place in a book, it keeps track of the point in the input stream where the computer should continue reading. The reading marker indicates the next character waiting to be read. The extraction operator &gt;&gt; leaves the reading marker on the character following the last piece of data that was input.</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">Each input line has an invisible end-of-line character (the <i>newline character)</i> that tells the computer where one line ends and the next begins. To find the next input value, the &gt;&gt; operator crosses line boundaries (newline characters) if it has to.</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">Where does the newline character come from? What is it? The answer to the first question is easy. When you are working at a keyboard, you generate a newline character yourself each time you hit the Return or Enter key. Your program also generates a newline character when it uses the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">endl</font><font face="Times New Roman, Times, Serif" size="3"> manipulator in an output statement. The </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">endl</font><font face="Times New Roman, Times, Serif" size="3"> manipulator outputs a newline, telling the screen cursor to go to the next line. The answer to the second question varies from computer system to computer system. The newline character is a nonprintable control character that the system recognizes as meaning the end of a line, whether it's an input line or an output 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="Times New Roman, Times, Serif" size="3">In a C++ program, you can refer directly to the newline character by using the two symbols \n, a backslash and an n with no space between them. Although \n consists of two symbols, it refers to a single characterthe newline character. Just as you can store the letter <i>A</i> into a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">char</font><font face="Times New Roman, Times, Serif" size="3"> variable </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ch</font><font face="Times New Roman, Times, Serif" size="3"> like this:</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_135.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_136</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_137.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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