Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 2/Input/zh CN: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Basic Pascal Tutorial/Chapter 2/Input/zh CN

OldNewLine
1+2A - 输入 (原作者: Tao Yue, 状态: 已更改)
2+
3+程序可以接收来自键盘、鼠标、文件、扫描仪、操纵杆的数据。
4+
5+我们不能得到鼠标的输入,因为语法不同。另外,现在视窗操作系统都支持事件驱动,它们可处理鼠标的输入。
6+
7+用于读取数据的基本格式是:
8+
9+``` pascal
10+read (变量列表);
11+readln (变量列表);
12+readln;
13+```
14+
15+变量列表是一系列以逗号分隔的变量标识符。
16+
17+写在括号中的变量,都需要预告先定义;变量与变量之间,以“,”分隔。
18+
19+从键盘接收数据时,要注意各种不同数据类型数据的分隔符不同。所谓分隔符就是两个完整的数值之间的标记,也可以这样理解,当计算机从键盘读入数据时,一旦碰到分隔符,就认为当前的数据读入已完成,可以把它赋给相应的变量了。各种数据类型的分隔符如下:
20+
21+数值型(包括整型、实型以及它们的子界类型)以空格或回车符作为分隔符; 字符型不需分隔符(因为字符型数据的长度固定,只有一个); 字符串以回车符作为分隔符。
22+
23+若多输入了数据(即数据个数超过变量个数),read语句读完数据之后,能让后续的读语句接着读取多下来的数据;而readln 语句对本行多输入的数据不能让后续语句接着读取多下来的数据。为了防止多输入的数据影响下一个输入语句读取数据,建议尽量使用readln语句输入数据。
24+
25+假设让用户输入4个整数,a、b、c、d:
26+
27+`45 97 3`\
28+`1 2 3`
29+
30+下面是`read`和`readln`语句,以及读取相应变量的值。
31+
32+<table>
33+<thead>
34+<tr>
35+<th>声明</th>
36+<th>a</th>
37+<th>b</th>
38+<th>c</th>
39+<th>d</th>
40+</tr>
41+</thead>
42+<tbody>
43+<tr>
44+<td>read (a);</td>
45+<td rowspan="2">45</td>
46+<td rowspan="2">97</td>
47+<td rowspan="2"></td>
48+<td rowspan="2"></td>
49+</tr>
50+<tr>
51+<td>read (b);</td>
52+</tr>
53+<tr>
54+<td>readln (a);</td>
55+<td rowspan="2">45</td>
56+<td rowspan="2" style="text-align: right;">1</td>
57+<td rowspan="2"></td>
58+<td rowspan="2"></td>
59+</tr>
60+<tr>
61+<td>read (b);</td>
62+</tr>
63+<tr>
64+<td>read (a, b, c, d);</td>
65+<td>45</td>
66+<td>97</td>
67+<td>3</td>
68+<td>1</td>
69+</tr>
70+<tr>
71+<td>readln (a, b);</td>
72+<td rowspan="2">45</td>
73+<td rowspan="2">97</td>
74+<td rowspan="2">1</td>
75+<td rowspan="2">2</td>
76+</tr>
77+<tr>
78+<td>readln (c, d);</td>
79+</tr>
80+</tbody>
81+</table>
82+
83+定义的变量列表,只能是变量,不能是[[Basic Pascal Tutorial/Chapter 1/Constants/zh CN|常量]]。
84+
85+# 外部链接
86+
87+[Read和ReadLn的区别](http://blog.csdn.net/JADE_BLACK/article/details/4087581)
88+
89+| | | |
90+|----|----|----|
91+| [[Basic Pascal Tutorial/Chapter 1/Solution/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 2/Output/zh CN|下一页]] |
92+
93+---
94+*From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 2/Input/zh CN", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history