在帕斯卡中给出字符串类型时出错



我在程序文件名之后和变量之前在我的 pascal 代码中定义了一个新的字符串类型,但它给出了一个错误"开始"预期的 Str20 找到。

Program Input_try_1;
Type Str20 : string[20];
Var f: file of Str20;
x : String;
EOF : Boolean;
begin
EOF := False;
Assign(f,'Dic.txt');
Rewrite(f);
Writeln('When you finish enter <End>');
While EOF = false do 
begin
Readln(x);
If x = 'End' then EOF := True
else Write(f,x);
end;

Close(f);
End.

我希望"类型 Str20:string[20]; 不会给出任何错误,并且无法理解问题。

在类型声明中,使用等号而不是冒号,如下所示:

Type Str20 = String[20] 

顺便说一句,你不需要定义自己的EOF,你可以使用内置的EOF函数:

while not Eof(x) do ...

这样,您就不需要源文件中的End

最新更新