学生记录要求有:名字,学号。(就两项)
 我想请教各位的是:假定学生信息在student.txt中,如何编写程序,读文件中的信息并把它输出???谢谢大家。在线等待。!!!!!!

解决方案 »

  1.   

    楼主,未免有点太懒,自己应该先查一些资料。type
      TStudent=record
        id: string[16];        //学号
        name: string[32];      //名字
      end;
      TStudents=record
        count: integer;
        recs : array of TStudent;
      end;//读取记录,同时记录存放在 students 中。
    function GetStudentsFromFile(fileName: string; var students: TStudents): boolean;
    var
      lpFile : file of TStudent;
      student: TStudent;
    begin
      result := false;
      if not FileExists(fileName) then
      begin
        ShowMessage('学生记录文件未找到!');
        exit;
      end;
      try
        AssignFile(lpFile,fileName);
        reset(lpFile);
        students.count := 0;
        while not Eof(lpFile) do
        begin
          read(lpFile,student);
          Inc(students.count);
          SetLength(students.recs,students.count);
          students.recs[students.count-1] := student;
        end;
        CloseFile(lpFile);
        result := true;
      except
        ShowMessage('系统异常,无效文件或文件读写错误!');
      end;
    end;
      

  2.   

    ....
    var
    thefile:textfile;
    filename,s_name,s_num:string;assignfile(thefile,filename);
    reset(thefile);
    readln(thefile,s_name);
    readln(thefile,s_num);
    closefile(thefile);
      

  3.   

    type 
      TStudent=record 
        id: string[16];        //学号 
        name: string[32];      //名字 
      end; 
      TStudents=record 
        count: integer; 
        recs : array of TStudent; 
      end; //读取记录,同时记录存放在 students 中。 
    function GetStudentsFromFile(fileName: string; var students: TStudents): boolean; 
    var 
      lpFile : file of TStudent; 
      student: TStudent; 
    begin 
      result := false; 
      if not FileExists(fileName) then 
      begin 
        ShowMessage( '学生记录文件未找到! '); 
        exit; 
      end; 
      try 
        AssignFile(lpFile,fileName); 
        reset(lpFile); 
        students.count := 0; 
        while not Eof(lpFile) do 
        begin 
          read(lpFile,student); 
          Inc(students.count); 
          SetLength(students.recs,students.count); 
          students.recs[students.count-1] := student; 
        end; 
        CloseFile(lpFile); 
        result := true; 
      except 
        ShowMessage( '系统异常,无效文件或文件读写错误! '); 
      end; 
    end;