关于读取文件

About reading file

  while (not eof(inputFile)) do begin 
     new(newNode); 
     read(inputFile, newNode^.student.index); 
     read(inputFile, temp); 
     newNode^.student.forename := ''; 
     read(inputFile, temp); 
     while (temp <> ' ') do begin 
newNode^.student.forename:=newNode^.student.forename+temp; {And what does this +temp mean } 
      read(inputFile, temp); 
     end; 
     newNode^.student.surname:= ''; 
     read(inputFile, temp); 
     while (temp <> ' ') do begin 

谁能给我解释一下这条线

   read(inputFile, temp)

为什么我们需要那个临时变量,它有什么用?

 temp:char;

Temp是字符类型,程序需要读取学生的名字和姓氏。是行

   read(temp) 

过剩?

在您的代码中,temp: char; 用于一次保存一个字符,从文件中读取。因为名字和姓氏在文件中被space分隔,所以你需要检测space,所以你可以将读取的字符分配给学生记录的正确字段。

如果 temp 将被声明为,例如string,整行(在索引之后)将被读入 forename 字段。

阅读名字的评论细分如下:

newNode^.student.forename := ''; // clear the forename field
read(inputFile, temp);           // read one character
while (temp <> ' ') do begin     // while the read character is not a space
  newNode^.student.forename:=newNode^.student.forename+temp; // concatenate with the field content
  read(inputFile, temp);         // read next character
end; 
// continue with rest of code when a space after the forename is detected

我不明白你关于 read(temp) 的最后一个问题。显示的代码中没有这样的行。如果您认为它过多,请将其移除并查看会发生什么。请务必了解如何在调试器中单步执行 运行 代码。