Sign in Join
Wiki copytemporary

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

Revision 4 to 5. 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```text
282845 97 3
29291 2 3
3030```
3131
3232下面是`read`和`readln`语句,以及读取相应变量的值。
3333
34-<thead>
35-
36-</thead>
37-<tbody>
38-
39-</tbody>
34+| 声明 | a | b | c | d |
35+|---|---|---|---|---|
36+| read (a); | 45 | 97 | | |
37+| read (b); | | | | |
38+| readln (a); | 45 | 1 | | |
39+| read (b); | | | | |
40+| read (a, b, c, d); | 45 | 97 | 3 | 1 |
41+| readln (a, b); | 45 | 97 | 1 | 2 |
42+| readln (c, d); | | | | |
4043
4144定义的变量列表,只能是变量,不能是[[Basic Pascal Tutorial/Chapter 1/Constants/zh CN|常量]]。
4245
4346# 外部链接
4447
4548[Read和ReadLn的区别](http://blog.csdn.net/JADE_BLACK/article/details/4087581)
4649
4750| | | |
4851|----|----|----|
4952| [[Basic Pascal Tutorial/Chapter 1/Solution/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 2/Output/zh CN|下一页]] |
5053
5154---
5255*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