Sign in Join
Wiki copytemporary

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

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

OldNewLine
112A - 输入 (原作者: Tao Yue, 状态: 已更改)
22
33程序可以接收来自键盘、鼠标、文件、扫描仪、操纵杆的数据。
44
55我们不能得到鼠标的输入,因为语法不同。另外,现在视窗操作系统都支持事件驱动,它们可处理鼠标的输入。
66
77用于读取数据的基本格式是:
88
99``` pascal
1010read (变量列表);
1111readln (变量列表);
1212readln;
1313```
1414
1515变量列表是一系列以逗号分隔的变量标识符。
1616
1717写在括号中的变量,都需要预告先定义;变量与变量之间,以“,”分隔。
1818
1919从键盘接收数据时,要注意各种不同数据类型数据的分隔符不同。所谓分隔符就是两个完整的数值之间的标记,也可以这样理解,当计算机从键盘读入数据时,一旦碰到分隔符,就认为当前的数据读入已完成,可以把它赋给相应的变量了。各种数据类型的分隔符如下:
2020
2121数值型(包括整型、实型以及它们的子界类型)以空格或回车符作为分隔符; 字符型不需分隔符(因为字符型数据的长度固定,只有一个); 字符串以回车符作为分隔符。
2222
2323若多输入了数据(即数据个数超过变量个数),read语句读完数据之后,能让后续的读语句接着读取多下来的数据;而readln 语句对本行多输入的数据不能让后续语句接着读取多下来的数据。为了防止多输入的数据影响下一个输入语句读取数据,建议尽量使用readln语句输入数据。
2424
2525假设让用户输入4个整数,a、b、c、d:
2626
2727`45 97 3`\
2828`1 2 3`
2929
3030下面是`read`和`readln`语句,以及读取相应变量的值。
3131
32-<table>
3332<thead>
34-<tr>
35-<th>声明</th>
36-<th>a</th>
37-<th>b</th>
38-<th>c</th>
39-<th>d</th>
40-</tr>
33+
4134</thead>
4235<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>
36+
8037</tbody>
81-</table>
8238
8339定义的变量列表,只能是变量,不能是[[Basic Pascal Tutorial/Chapter 1/Constants/zh CN|常量]]。
8440
8541# 外部链接
8642
8743[Read和ReadLn的区别](http://blog.csdn.net/JADE_BLACK/article/details/4087581)
8844
8945| | | |
9046|----|----|----|
9147| [[Basic Pascal Tutorial/Chapter 1/Solution/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 2/Output/zh CN|下一页]] |
9248
9349---
9450*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