【问题标题】:Error while giving type of string in Pascal在 Pascal 中给出字符串类型时出错
【发布时间】:2020-01-27 01:56:43
【问题描述】:

我在程序文件名之后和变量之前在我的帕斯卡代码中定义了一个新的字符串类型,但它给出了一个错误“开始”预期的 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.

我期待 'Type Str20:string[20];不会报错,看不懂问题。

【问题讨论】:

  • 在类型声明中,使用等号而不是冒号。类型 Str20 = String[20]
  • 哦哇非常感谢你:))

标签: string types pascal


【解决方案1】:

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

 Type Str20 = String[20] 

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

while not Eof(x) do ...

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

【讨论】:

    猜你喜欢
    • 2014-12-21
    • 2020-10-28
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多