在 Pascal 中给出字符串类型时出错
Error while giving type of string in Pascal
我在程序文件名之后和变量之前在我的 Pascal 代码中定义了一个新的字符串类型,但是它给出了一个错误 'Begin' expected Str20 found。
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.
我期待'Type Str20:string[20];不会报错,看不懂的问题
在类型声明中,您使用等号而不是冒号,如:
Type Str20 = String[20]
顺便说一句,您不需要定义自己的 EOF,您可以使用内置的 EOF 函数:
while not Eof(x) do ...
这样,您就不需要源文件中的 End
。
我在程序文件名之后和变量之前在我的 Pascal 代码中定义了一个新的字符串类型,但是它给出了一个错误 'Begin' expected Str20 found。
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.
我期待'Type Str20:string[20];不会报错,看不懂的问题
在类型声明中,您使用等号而不是冒号,如:
Type Str20 = String[20]
顺便说一句,您不需要定义自己的 EOF,您可以使用内置的 EOF 函数:
while not Eof(x) do ...
这样,您就不需要源文件中的 End
。